I am using the Python script manager to try and automate a few things. I am creating a hierarchy and I want to create an xpresso tag where the z offset of one cloner is driven by the z size of another cloner. Here's my code:
import c4d
from c4d import gui
import math
def main():
cloner = c4d.BaseObject(1018544) # cloner id
cloner[c4d.MG_LINEAR_OBJECT_POSITION,c4d.VECTOR_Y] = 0
cloner[c4d.MG_LINEAR_OBJECT_POSITION,c4d.VECTOR_Z] = 500
cloner[c4d.MG_LINEAR_COUNT] = 10
cloner[c4d.MGCLONER_VOLUMEINSTANCES] = True
doc.InsertObject(cloner)
newnull = c4d.BaseObject(c4d.Onull)
newnull.InsertUnder(cloner)
internal_cloner = c4d.BaseObject(1018544) # cloner id
internal_cloner.InsertUnder(newnull)
internal_cloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = 3 # 3 is grid array
internal_cloner[c4d.MG_GRID_SIZE] = c4d.Vector(300, 200, 100)
cube = c4d.BaseObject(c4d.Ocube)
cube.InsertUnder(internal_cloner)
cube[c4d.PRIM_CUBE_LEN] = c4d.Vector(20, 10, 100)
xtag = c4d.BaseTag(c4d.Texpresso) # create the xpresso tag
cloner.InsertTag(xtag)
# http://mograph.net/board/index.php?/topic/26338-creating-xpresso-nodes-with-python-script/
nodemaster = xtag.GetNodeMaster()
node1 = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 100, 100)
node1[c4d.GV_OBJECT_OBJECT_ID] = internal_cloner
node1out = node1.AddPort(c4d.GV_PORT_OUTPUT, (c4d.MG_GRID_RESOLUTION, c4d.VECTOR_Z))
node2 = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 300, 100)
node2[c4d.GV_OBJECT_OBJECT_ID] = cloner
node2in = node2.AddPort(c4d.GV_PORT_INPUT, (c4d.MG_LINEAR_OBJECT_POSITION, c4d.VECTOR_Z))
node1out.Connect(node2in)
c4d.EventAdd() # refreshed viewport to see changes automatically
# id = op.GetType()
if __name__=='__main__':
main()
Unfortunately, this does not work and gives me an "AttributeError: 'NoneType' object has no attribute 'Connect'.
When looking at the results, you can see that the first cloner never had its output port created:
What I'm wanting is this:
Can you please help me understand what I'm doing wrong in this code? Thank you.