Add a group to another group by rupy-code
-
Hi,
I would like to insert "Group1" into "Group2" by ruby-code.
What should I do to make this work? -
Lets call them
group1andgroup2
They must be in the same 'context'.
You then use a newly made temporary group to contain both groups and manipulate all of the three groups as needed...context = group1.parent ### e.g. 'model' group_temp = context.entities.add_group(group1, group2) ### now transfer all group1's properties to group_temp ### you can skip those that are definitely not needed for YOUR groups... group_temp.name = group1.name group_temp.description = group1.description group_temp.layer = group1.layer group_temp.material = group1.material group_temp.hidden = group1.hidden? group_temp.visible = group1.visible? group_temp.locked = group1.locked? group_temp.casts_shadows = group1.casts_shadows? group_temp.receives_shadows = group1.receives_shadows? group_temp.glued_to = group1.glued_to attrdicts=group1.attribute_dictionaries attrdicts.each{|attrdict| name = attrdict.name attrdict.each_pair{|key,value|newMat.set_attribute(name,key,value)} }if attrdicts ### Note; if 'group1' HAD "observers" you now need to add them to 'group_temp' too... group1.explode ### this puts the 'group1.entities' at the correct 'level' in the new container. ### IF you want group2's entities 'loose', rather than as the group itself, ### then add 'group2.explode' too... group1 = group_temp ### 'group1' now refers to the 'combined group' ### that now includes the original 'group1.entities' AND 'group2'... ### or 'group2.entities' if you exploded it too. -
@andreas said:
Hi,
I would like to insert "Group1" into "Group2" by ruby-code.
What should I do to make this work?Are you talking about existing groups? If so, refer to TIGs post.
If you are creating new groups via Ruby:
group1 = model.active_entities.add_group group2 = group1.entities.add_group
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement