Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Controlling Shader with Userdata

    Cinema 4D SDK
    3
    5
    1.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bencaires
      last edited by

      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]
      
      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        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.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • B
          bencaires
          last edited by

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

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            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.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            dskeithbuckD 1 Reply Last reply Reply Quote 0
            • dskeithbuckD
              dskeithbuck @m_adam
              last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post