Merge groups
-
Hello.
It's possible merge two groups into one group via ruby? Thanks.
-
Yes.
If the two groups are in the active_entities context then
group2=group0.parent.entities.add_group([group0, group1])
will work - however, if they are not in the active_entities context if will Bugsplat! big time!!!
Adding any entities to a group directly will cause disasters IF you cross-thread the entities' contexts. So it's always safer to use this way - you can write a method to use it repeatedly...def combine_groups(ents,group0,group1) d0=group0.entities.parent t0=group0.transformation d1=group1.entities.parent t1=group1.transformation group2=ents.add_group() g0=group2.entities.add_instance(d0,t0) g1=group2.entities.add_instance(d1,t1) ### remember the originals properties as needed l0=group0.layer m0=group0.material n0=group0.name d0=group0.description attrdicts0=g0.attribute_dictionaries g0.layer=l0 g0.material=m0 g0.name=n0 g0.description=d0 attrdicts0.each{|attrdict| name=attrdict.name attrdict.each_pair{|key,value|g0.set_attribute(name,key,value)} }if attrdicts0 l1=group1.layer m1=group1.material n1=group1.name d1=group1.description attrdicts1=g1.attribute_dictionaries g1.layer=l1 g1.material=m1 g1.name=n1 g1.description=d1 attrdicts1.each{|attrdict| name=attrdict.name attrdict.each_pair{|key,value|g0.set_attribute(name,key,value)} }if attrdicts1 ### group0.erase! group1.erase! ### return [g0, g1, group2] end#def
The usage is then
ents=group0.parent.entities ### or any entities context required group0,group1,group2 = combine_groups(ents,group0,group1)
Where the referencesgroup0
andgroup1
are transferred to the new instances of the groups, andgroup2
is the combined group containing them both.
If you want the contents of those two groups to merge then simply add this after thecombine_groups
line of code
group0.explode group1.explode
The contents of the newgroup2
are the combined entities of the now defunctgroup0
andgroup1
... -
TIG thank you very much.
Advertisement