Hi, here in Cinema 4D S22 defining the type of the cloner I don't have anymore an issue
import c4d
from c4d import gui
import math
def main():
# Build Parent Cloner
cloner = c4d.BaseObject(1018544)
cloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = c4d.ID_MG_MOTIONGENERATOR_MODE_LINEAR
doc.InsertObject(cloner)
# Build Null
newnull = c4d.BaseObject(c4d.Onull)
newnull.InsertUnder(cloner)
# Build Children Cloner
internal_cloner = c4d.BaseObject(1018544)
internal_cloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = c4d.ID_MG_MOTIONGENERATOR_MODE_GRIDARRAY
internal_cloner.InsertUnder(newnull)
internal_cloner.Message(c4d.MSG_MENUPREPARE, doc)
# Cube
cube = c4d.BaseObject(c4d.Ocube)
internal_cloner.Message(c4d.MSG_MENUPREPARE, doc)
cube.InsertUnder(internal_cloner)
# Xpresso Tag
xtag = c4d.BaseTag(c4d.Texpresso)
cloner.InsertTag(xtag)
# Setup Parent Cloner
cloner[c4d.MG_LINEAR_OBJECT_POSITION, c4d.VECTOR_Y] = 0.0
cloner[c4d.MG_LINEAR_OBJECT_POSITION, c4d.VECTOR_Z] = 500.0
cloner[c4d.MG_LINEAR_COUNT] = 10
cloner[c4d.MGCLONER_VOLUMEINSTANCES_MODE] = c4d.MGCLONER_VOLUMEINSTANCES_MODE_RENDERINSTANCE
# Setup Children Cloner
internal_cloner[c4d.MG_GRID_SIZE] = c4d.Vector(300, 200, 100)
# Setup Cube
cube[c4d.PRIM_CUBE_LEN] = c4d.Vector(20, 10, 100)
# Setup Xpresso
# 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
gridResParam = c4d.DescID(c4d.DescLevel(c4d.MG_GRID_RESOLUTION, c4d.DTYPE_VECTOR,0), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL,0))
node1out = node1.AddPort(c4d.GV_PORT_OUTPUT, gridResParam)
node2 = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 300, 100)
node2[c4d.GV_OBJECT_OBJECT_ID] = cloner
posParam = c4d.DescID(c4d.DescLevel(c4d.MG_LINEAR_OBJECT_POSITION, c4d.DTYPE_VECTOR,0), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL,0))
node2in = node2.AddPort(c4d.GV_PORT_INPUT, posParam)
# Connect
if node1out is not None and node2in is not None:
node1out.Connect(node2in)
c4d.EventAdd() # refreshed viewport to see changes automatically
if __name__=='__main__':
main()
And as pointed by @PluginStudent the problem was because the AddPort fails. And I guess it failed because at the time you ask for the port creation since no explicit mode was defined in the Cloner the XPresso description was not properly fed so this GvPort didn't exist.
Cheers,
Maxime.