Adding groups to an existing group
-
What am I missing. When the following code is executed it creates groups from each face but grpA, which I thought I was adding groups to, is empty?
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection grpA = ent.add_group; grpA.name="container" for f in ent.grep(Sketchup;;Face) grpB=grpA.entities.add_group f grpB.name="#{f.bounds.width} X #{f.bounds.height}" end puts "grpA contains #{grpA.entities.length} entities"
-
The '
entities.add_group(xxx)
' ONLY works if the 'xxx
' is in the 'active_entities
' AND 'entities
' IS the 'active_entities
'...
So you need to add those faces [that are also in the 'active_entities
'] directly into a group as you add it into the 'active_entities
', then add that new group directly into a second group that you then add into the 'active_entities
' etc...
Otherwise get a references to the group and use something like:
tr=Geom::Transformation.new()another_things_entities.add_instance(group.entities.parent, tr)
then erase the original group
group.erase!
leaving a 'clone' of it inside this other group...
???You are lucky not to get a Bugsplat when 'crossing entities'
-
Thanks TIG. I sure there is a logical explination as to why you have to add an instance to the container group and delete the original but seems strange to me. Anyway, using your suggestions, this is the modified code and it works just like I wanted.
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection grpA = ent.add_group; grpA.name="container" tr=Geom;;Transformation.new() for f in ent.grep(Sketchup;;Face) grpB=ent.add_group f; tr=grpB.transformation grpB.name="#{f.bounds.width} X #{f.bounds.height}" grpC=grpA.entities.add_instance(grpB.entities.parent,tr) grpC.name=grpB.name grpB.erase! end puts "grpA contains #{grpA.entities.length} entities"
Advertisement