SOLVED update User Data with Preset info

Hi, I am trying to use values from a preset to update/change a User Data field. The console prints out the correct value but the User Data field remains unchanged. Can you tell me what I am missing? Thanks.

import c4d

def main():

    neon = op.GetObject()
    UD = neon.GetUserDataContainer()

    g_dirty_glass_presets = neon[c4d.ID_USERDATA,185]
    g_smudges = neon[c4d.ID_USERDATA,183]
    g_dirt = neon[c4d.ID_USERDATA,192]
    g_scratches = neon[c4d.ID_USERDATA,189]
    g_scale = neon[c4d.ID_USERDATA,193]

    if g_dirty_glass_presets == 0:
        g_scratches = 5.0
        print g_scratches

Hi,

the atomic types of Python are all immutable. So doing something like

>>> x = my_node[c4d.ID_USER_DATA, 1]
>>> type(x)
<type 'int'>
>>> x = 5

will only change the local copy reference of that immutable type.

If you want to copy an immutable attribute, you will have to copy from node to node. Here is an example for copying an integer from node_a to node_b only if the integer in node_a equals 0.

if if node_a[c4d.ID_USERDATA, 1] is 0:
   node_a[c4d.ID_USERDATA, 1] = node_b[c4d.ID_USERDATA, 1]

Cheers,
zipit

Hi,

the atomic types of Python are all immutable. So doing something like

>>> x = my_node[c4d.ID_USER_DATA, 1]
>>> type(x)
<type 'int'>
>>> x = 5

will only change the local copy reference of that immutable type.

If you want to copy an immutable attribute, you will have to copy from node to node. Here is an example for copying an integer from node_a to node_b only if the integer in node_a equals 0.

if if node_a[c4d.ID_USERDATA, 1] is 0:
   node_a[c4d.ID_USERDATA, 1] = node_b[c4d.ID_USERDATA, 1]

Cheers,
zipit

This is from another scene I made. It resets User Data by inserting values when a button is clicked on. The button then resets. This code works. Why is the other code I posted not working?

import c4d


def main():

    ID_RESET_Classic_Beer = 29
    ID_RESET_Cool_Pop = 412
    ID_RESET_Dew = 413
    ID_RESET_Fridge = 414
    ID_RESET_Summer = 415
    ID_RESET_Mountain = 416
    ID_RESET_Cooler = 417
    ID_RESET_Picnic = 418
    ID_RESET_Heat_Wave = 419
    ID_RESET_Drive_in = 420
    ID_PRESET = 13

    rig = op.GetObject()

        # reset Classic Beer
    if rig[c4d.ID_USERDATA, ID_RESET_Classic_Beer]:
        rig[c4d.ID_USERDATA, ID_RESET_Classic_Beer] = False

        rig[c4d.ID_USERDATA, 196] = 0       # Classic Beer MASTER Coalesce
        rig[c4d.ID_USERDATA, 197] = 1       # Classic Beer Coalesce Amount
        rig[c4d.ID_USERDATA, 198] = 1       # Classic Beer BIG and SMALL Random Scale
        rig[c4d.ID_USERDATA, 199] = 3       # Classic Beer Mesh Density

        rig[c4d.ID_USERDATA, 201] = 1       # Classic Beer BIG Drops
        rig[c4d.ID_USERDATA, 202] = 500     # Classic Beer BIG Amount
        rig[c4d.ID_USERDATA, 203] = 3       # Classic Beer BIG Size
        rig[c4d.ID_USERDATA, 204] = 26085   # Classic Beer Random Seed BIG

        rig[c4d.ID_USERDATA, 206] = 1       # Classic Beer SMALL Drops
        rig[c4d.ID_USERDATA, 207] = 800     # Classic Beer SMALL Amount
        rig[c4d.ID_USERDATA, 208] = 1.6     # Classic Beer SMALL Size
        rig[c4d.ID_USERDATA, 209] = 24338   # Classic Beer Random Seed SMALL

        rig[c4d.ID_USERDATA, 211] = 1       # Classic Beer MICRO Drops
        rig[c4d.ID_USERDATA, 212] = 2000    # Classic Beer MICRO Amount
        rig[c4d.ID_USERDATA, 213] = 3       # Classic Beer MICRO Size
        rig[c4d.ID_USERDATA, 214] = .18     # Classic Beer MICRO Strength
        rig[c4d.ID_USERDATA, 215] = 28643   # Classic Beer RANDOM Seed MICRO

        rig[c4d.ID_USERDATA, 190] = 0       # Classic Beer MIST Off On
        rig[c4d.ID_USERDATA, 191] = 1000    # Classic Beer MIST Amount
        rig[c4d.ID_USERDATA, 192] = 1       # Classic Beer MIST Droplet Size
        rig[c4d.ID_USERDATA, 193] = 12345   # Classic Beer Random Seed MIST
        rig[c4d.ID_USERDATA, 194] = 2       # Classic Beer Random Scale MIST

        c4d.EventAdd()

Okay, this code works:

import c4d

def main():

    neon = op.GetObject()
    UD = neon.GetUserDataContainer()

    g_dirty_glass_presets = neon[c4d.ID_USERDATA,185]
    g_smudges = neon[c4d.ID_USERDATA,183]
    g_dirt = neon[c4d.ID_USERDATA,192]
    g_scratches = neon[c4d.ID_USERDATA,189]
    g_scale = neon[c4d.ID_USERDATA,193]

    g_ext = neon[c4d.ID_USERDATA,25]

    reset = neon[c4d.ID_USERDATA,229]

    if neon[c4d.ID_USERDATA,185] == 0:
        neon[c4d.ID_USERDATA,189] = 5

I have set neon[c4d.ID_USERDATA,189] to a float. How would I set it to a gradient? How would I set it to a 2D vector? Thanks.

Hi,

you cannot, because the data container of a BaseList2D is not dynamically typed (like Python itself), but bound to data types specified in its description. If you want to change the data type of an user data element, you will have to modify the description of that element via GetUserDataContainer and SetUserDataContainer. There is also no 2D-Vector type in Cinema, only the crosshair thing custom GUI which you can apply to a Vector description element.

Cheers,
zipit