Learning Ruby for SketchUp

There are also “Basics in programming” tutorials specific to Ruby. But for many people, learning programming theoretically (from begin to end of a book) is not the best way. Often people bring already some experiences and want to pick up what enhances their knowledge. And also the strongest accelerator is having your own (little) “project”. That said, we have had a lot of beginners trying to start with a “big thing” without having an understanding of basics (like variable scope).

Refer to these resources:

If you have some understanding of programming and want to focus on SketchUp, jump to the SketchUp-specific section.
If you want don’t want to spend much time learning the language, get a feeling for the language with Try Ruby.

SketchUp’s Ruby API is modelled after the scene graph that are used to as a modeller (entities, components, materials). The principle of exploratorive learning is that you get a reference to something (e.g. a selected entity), find out its class, then go in the SketchUp Ruby documentation to the page for this class. It lists all methods that are available. After trying out a method, you can proceed with the returned value the same way.

groups = Sketchup.active_model.entities.grep(Sketchup::Group)
groups.each{ |group| group.move!([10,-50,100]) }

Not difficult!

3 Likes