Insert under with itertools
On 29/01/2018 at 14:09, xxxxxxxx wrote:
python noob here.
I have 2 lists with objects declared by their name as string. I align the matrix of the corresponding objects using itertools:
for J,N in itertools.izip(list1,list2) :
That works very well. But now I also want to insert the objects from list1 also under the objects from list2 in the OM as children. I get now the error "list object has no attribute insertUnder". Ok, is there a workaround how to do that?
On 30/01/2018 at 02:14, xxxxxxxx wrote:
welcome to the Plugin Café forums
I'm not so sure about the first part of your description. In Cinema 4D Objects (BaseObject) are derived from (among other classes) GeListNode, which basically represents a node in the Object Manager tree. The functions to insert children are GeListNode.InsertUnder() (note the capital I) or InsertUnderLast().
If this does not solve your issue, please provide us with more code, so we can get a better understanding of your situation.
On 14/02/2018 at 09:12, xxxxxxxx wrote:
thanks for the answer. For an artist with very basic coding skills it is not so easy to even know what to look for in the SDK. That is the structre I prefer to use since I have an overview in the code about the 2 objects that go together:
from c4d import gui
Nulls = ["Null1", "Null2" , "Null3" , "Null4"]
PositNull = ["N_Null1","N_Null2","N_Null3", "N_Null4"]
def main() :
for J,N in itertools.izip(Nulls,PositNull) :
obj = doc.SearchObject(J)
if obj is None: return False
matrix = obj.GetMg() #the global matrix
globalPos = matrix.off #get the position from the matrix
obj2 = doc.SearchObject(N)
if obj2 is None: return False
matrix2 = obj2.GetMg() #the global matrix
globalPos2 = matrix2.off #get the position from the matrix
m = matrix2
m.off = globalPos2 #get the position from the Object Matrix
obj.SetMg(m) #Sets the global matrix of 1 to 2
Now I want to add the feature that the according objects align in OM hierarchy as well.