Normal day at the ENGworks office. We were assigned to place 1000+ trees components over a sloped terrain surface in Sketchup.
The good old “Move + cursor Up” to snap to a Z point is useful, but after the tree number 50th you start feeling the task is titanic.
Since a its beginnings, Sketchup support Ruby scripting and had a vast collection of plugins created by the community – now Extension Warehouse. With this in mind, we started looking for add-ins that could do this simple task for use.
Surprisingly for us we couldn’t find any solution to our specific problem performing a batch snapped movement and that’s when we then remember the software came with a basic Ruby interpreter built in. The solution to our problems
[…] we then remember the software came with a basic Ruby interpreter built in. The solution to our problems.
A little google pointed us to a Raytrace function that makes exactly what we need.
Important note, we need to define the name of the surface as “terrain” in order to filter it from the rest of the elements and selected all elements we wanted to move (surface included)
After that we executed the following code directly from the Ruby interpreter.
What it does?
First, we got a list of all elements in the selection.
We filtered the elements by name to detect the surface and create a list with the remaining elements.
Functions to Raytrace and Move were defined and executed on each one of the elements pulling them up ( 0,0,1 vector = Z coordinate ) to the point were they meet the surface.
With this small code we saved ours on a repetitive task
The result? All trees placed at the right elevation over the terrain.
Disclaimer: I’m not a Ruby developer and this was the first time facing it so the code may be ugly but I found my self liking its python-ish way of coding.