Hello! I’m learning Ruby and have been trying a lot of tutorials, but getting frustrated with the steep learning curve to get me off the ground.
I’d like to write a script that takes a selected group in a sketch, makes a copy, moves and rotates that copy, then repeats, copying the original selection and moving that copy. The idea is to sketch a complex shape and then use that shape as faces in polyhedron, with the script doing all the copying, moving and rotating for me.
I’d love it if someone could post some a piece of code that could get me started. Thank you!
(My first draft will simply be making 8 copies and arranging them in an octahedron “brute-force”. Later I’d like to define vectors and move the groups with their centers on the ends of those vectors and rotated so that the x-plane for example is normal to those vectors.)
(1) In order to use the SketchUp API, you’ll first need to learn core Ruby. (I created a wikilist of catagorized learning resources in the Ruby API forum category.)
The repeating (looping) constructs are part of core Ruby, which has an
Enumerable library module that is “mixed-into” most collection type classes, that adds in even more looping methods.
(2) The best way to learn SketchUp scripting is to look at the examples in the Examples and Utilities example extensions of the SketchUp Team. Use them as templates, changing the outermost namespace module name to something unique for you.
Start simple, by creating 2D geometry on the ground plane. (You’re failing because you are attempting to jump ahead immediately to a complex 3D task.)
When you master simple tasks, move incrementally to more and more complex tasks, and study more complex examples.
(3) Copying, moving and rotating requires learning to create transformations, and apply them to groups and component instances.
This is fine, which would mean the origin for the group would be the center of the group. (Transformations are based on the origin of the instance, so you’d draw the face edges relative to a center origin.)
Dan, I very much appreciate your helpful advice - not just giving an answer but setting me on a path towards success. Thank you!