Have a function that creates a new instance of selected object (or, child of selected for now) - that works. Have functions that creates Cycle UserData on selected object, then populates with its children - that works. Next step I thought would be a breeze is creating the User Data "on" the newly created instance. Im pretty new to python so im sure theres a blatantly obvious way to do It I keep dancing around.
In my head, I think I want to pass the result of my createInstance function into my AddData function, but any means I try to do so gives me errors or no result. This version of my script is just from an arbitrary point so may be some other weirdness you could point out, just piecemealing at the moment.
C4D R20
import c4d
from c4d import gui
def createInstance(): # create Instance of Child of Selected Object
if op is None:
return
obj = c4d.GeListNode.GetDown(op)
inst = c4d.InstanceObject()
inst.SetReferenceObject(obj)
return obj
c4d.EventAdd()
def AddLongDataType(obj): # create User Data Container named Picker
if obj is None: return
bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG)
bc[c4d.DESC_NAME] = "Picker"
obj.AddUserData(bc)
c4d.EventAdd()
def setQuickTab(obj, data): # change User Date container to type Cycle, populate with Children Names
descid = data[0][0]
bc = data[0][1]
# Get the number of child objects
parent = doc.GetActiveObject()
count = len(parent.GetChildren())
H = c4d.GeListNode.GetChildren(parent)
# Build new cycle options container dynamically
cycle = c4d.BaseContainer()
for i in range (0,count):
child = H[i]
n = c4d.BaseList2D.GetName(H[i])
cycle.SetData(i, n)
bc[c4d.DESC_CYCLE] = cycle
# Set modified description data container
obj.SetUserDataContainer(descid, bc)
# Notify Cinema 4D for changes
c4d.EventAdd()
def main():
AddLongDataType(obj)
data = obj.GetUserDataContainer()
setQuickTab(obj, data)
doc.StartUndo()
doc.InsertObject(inst)
doc.AddUndo(c4d.UNDO_NEW, inst)
doc.EndUndo()
if __name__=='__main__':
main()