I am using .rb script to manipulate a scene in SketchUp. The script works fine in older version (SketchUp Pro 2013), but when trying to port it to SketchUp Pro 2016, it’s not behaving correctly.
Best guess, is that in the newer version of SketchUp pro, the script is operating on the full model/scene rather than just specific items.
Here’s the original code, which works find in SketchUp Pro 2013, but doesn’t work in SketchUp Pro 2016
def array_columns()
model = Sketchup.active_model
entities = model.active_entities
rotation_center = Geom::Point3d.new [140,130,0]
rotation_vector = Geom::Vector3d.new [0,0,1]
current_angle = 30
t1 = Geom::Transformation.rotation rotation_center,rotation_vector,current_angle.degrees
t2 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
t3 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
t4 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
t5 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
t6 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
t7 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
t8 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
t9 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
t10 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
t11 = Geom::Transformation.rotation rotation_center,rotation_vector,(current_angle += 30).degrees
entities.each { |entity|
if entity.class == Sketchup::Group
src_group = entities.add_group entity.to_a
dest_group1 = src_group.copy
finalgroup1 = dest_group1.transform! t1
dest_group2 = src_group.copy
finalgroup2 = dest_group2.transform! t2
dest_group3 = src_group.copy
finalgroup3 = dest_group3.transform! t3
dest_group4 = src_group.copy
finalgroup4 = dest_group4.transform! t4
dest_group5 = src_group.copy
finalgroup5 = dest_group5.transform! t5
dest_group6 = src_group.copy
finalgroup6 = dest_group6.transform! t6
dest_group7 = src_group.copy
finalgroup7 = dest_group7.transform! t7
dest_group8 = src_group.copy
finalgroup8 = dest_group8.transform! t8
dest_group9 = src_group.copy
finalgroup9 = dest_group9.transform! t9
dest_group10 = src_group.copy
finalgroup10 = dest_group10.transform! t10
dest_group11 = src_group.copy
finalgroup11 = dest_group11.transform! t11
break
end
}
UI.messagebox("Array columns completed")
end
After changing this section
entities.each { |entity|
if entity.class == Sketchup::Group
src_group = entities.add_group entity.to_a
To this (based on the this thread Move all entities to new group)
entities.each { |entity|
if entity.class == Sketchup::Group
src_group = model.entities.add_group(entities.to_a)
Here’s what it looks like with the modification to the code:
I found that the that the columns will are now placed around the target layout, but the entire scene in the model is duplicated. I only need the columns to be filled in.
I have been reading through the API documentation, but I haven’t been able to figure out where I’m going wrong.
Any assistance is appreciated.