Is there some kind of "set parent" method to "move" a Group inside a container?


#1

In my experience scripting in Vectorworks, there was a way of ‘moving’ an object from inside a container to another one, a function called SetParent.

I would like a method to move a Group inside a ComponentInstance, like a user would at the Outliner window!


Apply a model transformation to an entity in a component instance
#2

I need to point out an error in your thinking.

Component Instances do not “have” entities. It is Component Definitions that “have” (or “own”) an entities collection.

All instances of a certain definition will share the parent’s entities collection.

So you’d actually move a group instance, into a definition’s entities collection.

Perhaps something like:

cdef.entities.add_instance( grp.definition, grp.transformation )
grp.erase!

But there was some caveat concerning context. I cannot remember off hand what it is.

Perhaps @TIG knows ?


#3

Thanks Dan!

I understand your point, the container is the ComponentDefinition not the Instance (a mere reference placed in the drawing).

I’m doing exactly the .add_instance thing, using group.entities.parent for versions before 2015.

Is this the only way? For instance (no pun intended), adding a component to a container/ComponentDefinition I lose the ‘externally’ applied materials…

Cheers!


#4

To ‘Move’ a group into another context and keep all of its original ‘properties’ - so it appears you have haven’t actually ‘Copied’ it - you make references to them apply them to the new ‘instance’, then erase the original group…

grp ### the reference to the original group
newgrp = cdef.entities.add_instance( grp.entities.parent, grp.transformation )
newgrp.material = grp.material
newgrp.layer = grp.layer
newgrp.name = grp.name
attds = grp.attribute_dictionaries
attds.each{|d|
  n = d.name
  d.each_pair{|k, v|
    newgrp.set_attribute(n, k, v)
  }
} if attds
### you can also transfer any other properties like hidden?, locked? etc
grp.erase!

What is the proper way to make two groups interact?
#5

Wow! Thank you so much for the code!