Controlling Shader with Userdata



  • Hey,

    I'm trying to control a shader from some userdata but I keep getting this error:

    Traceback (most recent call last):
    File "'Python'", line 6, in main
    AttributeError: parameter access failed

    I'm not sure what I'm missing here.

    https://www.dropbox.com/s/0pvpjbiiofqdwg5/LinkShader_Py.c4d?dl=0

    import c4d
    
    
    def main():
        ShaderOb = op[c4d.ID_USERDATA,3]
        ShaderOp = op[c4d.ID_USERDATA,c4d.ID_MG_SHADER_SHADER]
        ChannOp = op[c4d.ID_USERDATA,c4d.ID_MG_SHADER_CHANNELSELECT]
        
        
        ShaderOb[c4d.ID_MG_SHADER_SHADER] = op[c4d.ID_USERDATA,c4d.ID_MG_SHADER_SHADER]
        ShaderOb[c4d.ID_MG_SHADER_CHANNELSELECT] = op[c4d.ID_USERDATA,c4d.ID_MG_SHADER_CHANNELSELECT]
    

  • Global Moderator

    Hi Bencaires,

    I can confirm there is a bug in C4D when you drag and drop a user data parameter into the console from your scene, the wrong ID is written.
    With that's said if you open the User Data Manager (In the description of an object, in the top menu, User Data => Manage User Data ...). Select your User Data parameter then below the name/short name you get the actual ID of this parameter.

    So in your case, if you write the correct ID, your script is working nicely.

    import c4d
    
    def main():
    	ShaderOb = op[c4d.ID_USERDATA, 3]
    	ShaderOp = op[c4d.ID_USERDATA, 10]
    	ChannOp = op[c4d.ID_USERDATA, 2]
    	
    	ShaderOb[c4d.ID_MG_SHADER_SHADER] = op[c4d.ID_USERDATA, 10]
    	ShaderOb[c4d.ID_MG_SHADER_CHANNELSELECT] = op[c4d.ID_USERDATA, 2]
    

    Cheers,
    Maxime.



  • Thank you m_adam that works perfectly now. Is that bug in all versions of cinema?


  • Global Moderator

    Yes, the issue comes from the fact you have created user data by Copying User Data interface from the shader interface (nothing wrong here).
    But when you copy and paste user data Interface due to a bug, the previous ID is kept and used when drag and dropping this parameter.



  • @m_adam I've run into the copy/paste UserData bug a few times. Glad it's been reported!