Groups, Instances and Entities...
-
I know this subject seems to go on for ever but I've come across a particularly interesting bug and wanted to share it. We have an instance with a bunch of entities that we can capture in an array. That should look something like
a = instance.definition.entities.to_a
Theoretically I should now be able to group the entities like this (I am using Sketchup
instance.definition.entities.add_group a
What is particularly interesting about this is that if I am in an edit session within the instance all works fine. If I am outside the instance strange things start happening. The group appears outside but is not clickable and disappears when I enter the edit session. If I delete the instance and click on the group I get a bug splat. Wierd
Anyone care to shed some light as to what is going on?
-
Yes, it's prone to oddities. There's a few threads here on that topic: add_group site:http://forums.sketchucation.com
http://forums.sketchucation.com/viewtopic.php?f=180&t=39518#p349216
-
This a long and established limit.
You should only ever use
grp=ents.add_group(array)
when the array of entities is in the active_entities context - hence the success during an edit but a failure during another session where the objects you are trying to group are not within the active context...
You can do a workaround making an empty group and adding duplicates of the objects to that group.
For groups/instances you can simply add another instance, but for other objects you need to 'clone' them, making duplicates of raw geometry edges/faces etc replicating their layer/material/hidden-state/attributes etc.
It's often easier to create these objects in the correct context initially, but there are times when you want to affect existing things...
So if you have two groups [grp1,grp2] inside another group [grp] that you want to 'combine' inside a single group [grp3], use this approach.
grp3=grp.entities.add_group() g1=grp3.entities.add_instance(grp1.entities.parent, grp1.transformation) g2=grp3.entities.add_instance(grp2.entities.parent, grp2.transformation) grp1.erase! grp2.erase!
Now 'grp' contains 'grp3' which contains 'grp1' and 'grp2'.
If you wanted to merge the contents of these two groups I've left you two references...
g1.explode g2.explode
Now 'grp' contains 'grp3', which contains all of the entities that were previously inside 'gr1' and 'g2' [i.e. they are now 'exploded'].This has been covered in several posts... if you trawl through them... as thomthom suggests...
-
Sorry for rehashing old problems. I did look around the forums. Guess I just wasn't looking properly. Your reply was clear and concise TIG. I tried your code out and it worked a charm. Cheers!
Advertisement