cinema4d_py_sdk icon indicating copy to clipboard operation
cinema4d_py_sdk copied to clipboard

Python Script - alternative to descId query

Open agapbetween opened this issue 5 years ago • 3 comments

Hi,

So I'm writing a plugin for Cinema 4D, and I'm running into an issue with a very specific python script. The python script is applied to a python tag, attached to a Null Object. Within the Null Object, there are custom User Data parameters assigned, to control functions of the plugin. Essentially what I'm trying to achieve is when a specific boole check box is checked, specific parameters to a feature of this plugin disappear. When the boole check box is unchecked, the specific parameters to the aforementioned features return.

The example below works as a test. However, the issue I'm running into is that when I change the integer value of "1" to any other integer (for example, say "4" for a specific User Data ID, for the descId, (which I thought was used to identify the User Data of a specific feature, like a boole checkbox), the script no longer works.

It seems that the only integer that's accepted in this script is the value of "1".

If that's the case, is there an alternative to descId, to target higher integer values related to specific User Data IDs?

The following is what I have written, which works (as a test) with the value "1" integer for the descId:

#Beginning example

import c4d #Welcome to the world of Python

def main():

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

LightOnOff = 1
ReflectiontEnabled = 3
NewLightOnOff = 4
SkyEnabled = 5

for descId, container in UD:
    
    theID = descId[1].id
    if theID == SkyEnabled:
        
        if obj[c4d.ID_USERDATA, 1] == 1:
            container[c4d.DESC_HIDE] = True
            obj.SetUserDataContainer(descid, container)
            
        if obj[c4d.ID_USERDATA, 1] == 0:
            container[c4d.DESC_HIDE] = False
            obj.SetUserDataContainer(descid, container)
            
    if theID == ReflectiontEnabled:
        
        if obj[c4d.ID_USERDATA, 1] == 0:
            container[c4d.DESC_HIDE] = True
            obj.SetUserDataContainer(descid, container)
            
        if obj[c4d.ID_USERDATA, 1] == 1:
            container[c4d.DESC_HIDE] = False
            obj.SetUserDataContainer(descid, container)

#End example

agapbetween avatar Apr 11 '19 23:04 agapbetween

Update:

So I got the function working, but the console is still showing an error, even though the function works.

I solved the issue by changing the following "theID = descId[4].id" to "theID = descId[c4d.ID_USERDATA, 4].id"

Even though the function now works, the console is reporting the following error:

"Traceback (most recent call last): File "'Python'", line 14, in main SystemError: Objects/longobject.c:237: bad argument to internal function Traceback (most recent call last): File "'Python'", line 23, in main SystemError: Objects/longobject.c:237: bad argument to internal function"

Any ideas?

agapbetween avatar Apr 12 '19 02:04 agapbetween

Hi @agapbetween for Cinema 4D Development questions please contact us on https://plugincafe.maxon.net/ Github is used only, for example, so please use issue on GitHub only to report an issue in one of the examples.

Cheers, Maxime.

gr4ph0s avatar Apr 12 '19 08:04 gr4ph0s

@gr4ph0s Thanks for the heads up, Maxime!

Cheers!

agapbetween avatar Apr 12 '19 08:04 agapbetween