I am new to Sketchup Ruby and am blown away this is not more simple but here goes...
I would like to copy all the groups matching a certain layer name to a new temporary group. I have basically given up on trying to copy the whole group because that appears to be fraught with peril and Bugsplats if not done in some super-anal retentive way that considers context, immediate exploding of objects, etc...
So, I have resorted to trying to loop through all matching groups entities and copying faces instead, which seems much more straight-forward. My goal here is not to become a Ruby wizard but just accomplish this one script.
I have been able to copy faces BUT the faces lose their transformation on copy and just end up at some random size at the origin rather than wherever they were at the model.
Here is the code:
SKETCHUP_CONSOLE.clear
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
temp_wall_primitives = ent.add_group #create a new empty temporary group
mod.definitions.each{|d|
next if d.image? || d.group? || d.name!="WALL"
d.entities.each{ |wall_primative_group|
if wall_primative_group.layer.name == "WALL_PRIMITIVES"
wall_primative_group.entities.each{ |wall_primative_group_entity|
if wall_primative_group_entity.is_a? Sketchup::Face
new_face = temp_wall_primitives.entities.add_face(wall_primative_group_entity.vertices)
end
}
end
}
}
I believe I need to somehow get the transformation of each face and apply it to the new faces as they are created?