[✓]Access user data of clones in Python Effector

On 31/05/2017 at 01:52, xxxxxxxx wrote:

Hey fellow C4D Devs!

I am trying to set user data of clones inside a python effector. The reason I'm want to achieve this is because Arnold can access user data and thus influence shading on a clone by clone basis. 
I was able to hackishly do this by putting the data into c4d.MODATA_COLOR (which Arnold can read as well) but this is obviously pretty limited.

I figure there must be *some* concept of user data storage per clone, from this example:

(Full image: http://i.imgur.com/WrCEQBK.png)

The cloner is set to blend, which also seems to interpolate the user data field used to scale the clones.

The original example scene is here, btw: http://mograph.net/board/index.php?showtopic=25915&p=195979

Any hints greatly appreciated!

On 01/06/2017 at 08:36, xxxxxxxx wrote:


welcome to the Plugin Café forums :slightly_smiling_face:

The referenced scene actually does not do, what you expect it to do. The user data scale parameter is only linked to the scale of the two cubes via Xpresso. The MoGraph cloner takes these cubes clones them into the array and while doing so, it blends between the two given cubes (not touching user data at all). On top of that the clones get influenced by the random effector.

It's not possible to have individual user data on the clones generated by a MoGraph cloner. The clones are just instances and their individual data is stored in the MoData. Of course you can use user data to influence the behavior of a Python Effector, just not on a per clone basis.

But you can add your own custom MoData arrays in a Python Effector, although I'm not sure how you'd access these inside Arnold. But roughly it looks like so, code for Python Effector:

    MY_ARRAY_ID = 123456 # have a unique ID from Plugin Cafe
    md = mo.GeGetMoData(op)
    if md is None:
        return False
    # A proper DescID is needed for AddArray()
    # Especially set the correct data type here!
    did = c4d.DescID(c4d.DescLevel(MY_ARR_ID, c4d.DTYPE_LONG, 0))
    myArr = md.GetArray(MY_ARR_ID)
    if myArr is None: # check, if the array has already been added earlier on
        idxArr = md.AddArray(did, "my array", 0)
        if idyArr == c4d.NOTOK:
            print "Error" # handle error here
            return False
    # Finally fill the array with your data
    md.SetArray(MY_ARR_ID, your data, True)

Of course a second Python Effector could now access this custom array in the same fashion.

On 06/06/2017 at 00:48, xxxxxxxx wrote:

Thanks Andreas for the thorough answer!
I am sticking to the c4d.MODATA_COLOR array for now, since it's quite easy and does what I need in my case. Will post here again once I have tried custom MoData arrays.