Batch edit component glue to

How can I batch edit 50 components at once using Ruby?

I regularly have to set the alignment to “any” on large numbers of components imported from Rhino.

For ALL definitions loaded …

model = Sketchup.active_model
dlist = model.definitions
dlist.each do |cdef|
  cdef.behavior.snapto= SnapTo_Arbitrary

EDIT: We must set the is2d property true as well in order for any of the #snapto values (and the #cuts_opening flag) to become active. (Treat the is2d property as if it’s name is “gluable”. Ie, in the GUI, when you select Glue to “None”, is2d is unset as false. Choosing any other #snapto value sets that value, but also sets is2d to true.)

model = Sketchup.active_model
dlist = model.definitions
dlist.each do |cdef|
  cdef.behavior.is2d= true
  cdef.behavior.snapto= SnapTo_Arbitrary

Now, you might not need to change the #snapto value, if the Rhino author (or it’s SketchUp exporter) only failed to set the is2d property, but the value of the #snapto property was correctly set (say to horizontal, vertical or sloped.)

Thanks, it worked on a component where I first set the glue to dropdown from ‘None’ to ‘Horizontal’.

The script changed it to ‘Any’

However all my components are set to ‘None’ first so there still is a problem?

Weirdly, there are only 4 allowable arguments as listed in the doc …

  1. SnapTo_Arbitrary => Snap to any arbitrary face,
  2. SnapTo_Horizontal => Snap to horizontal face like floors,
  3. SnapTo_Vertical => Snap to vertical face like walls,
  4. SnapTo_Sloped => Snap to sloped face like sloping roofs.

If we attempt to set it to 4 or -1 or nil we get an ArgumentError that the arg is out of the range 0..3.

When I first load a component manually in the application, I test the #snapto value and it is 0 and displays as “None” in the GUI.
If I change it to something other than 0, then change it back, the GUI displays “Any” (which is arbitrary, the first choice.)

@thomthom previously opened an API documentation issue on this subject …

So it seems we must set 2 API properties to get the result we want. (The GUI does it for the user automatically.)

So we need to edit the above snippet, in order to be sure that the #snapto value is applied rather that “None”. Ie, there is a boolean “gluable” property that has a weird name (is2d) that if false will display as #snapto “None” no matter what the actual #snapto value is (and also affects the #cuts_opening flag.)

Code snippet above edited.

Thanks for the help. Now it works the way I imagined.

1 Like