Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to insert a shader UserData field

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 376 Views
    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.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 25/11/2012 at 03:26, xxxxxxxx wrote:

      Hi People.

      I am trying to insert a shader field into the UserData of an object. It almost works, but there is a problem I could not yet solve. The UserData field is inserted successfully and shows up in the Attribute Manager. But I cannot insert a shader into it, it just doesn't work. When viewing the field in the UserData manager, I can see the "Interface" part missing.

      "Shader Field" was inserted by my code, "Data" was inserted using the UserData manager.

      This is the exact code I use:

          def add_shader_pressed(self, op) :  
            name = c4d.gui.RenameDialog('Shader Field')  
            if not name:  
                return  
        
            accept = c4d.BaseContainer()  
            accept.SetString(c4d.Tbaselist2d, "")  
        
            container = c4d.BaseContainer()  
            container.SetString(c4d.DESC_NAME, name)  
            container.SetString(c4d.DESC_SHORT_NAME, name)  
            container.SetLong(c4d.DESC_VERSION, c4d.DESC_VERSION_ALL)  
            container.SetBool(c4d.DESC_ANIMATE, True)  
            container.SetLong(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_TEXBOX)  
            container.SetContainer(c4d.DESC_ACCEPT, accept)  
            container.SetBool(c4d.DESC_SCALEH, True)  
            container.SetLong(c4d.DESC_PARENTGROUP, c4d.ID_USERDATA)  
        
            # Search for a free UserData id.  
            free_id = 1  
            userdata = sorted(op.GetUserDataContainer(), key=lambda x: x[0][0].id)  
            for id, data in userdata:  
                uid = id[1].id  
                if uid >= free_id:  
                    free_id = uid + 1  
        
            # Insert the shader field into the objects' UserData.  
            descid = c4d.DescID(c4d.DescLevel(700), c4d.DescLevel(free_id))  
            success = op.SetUserDataContainer(descid, container)  
            if not success:  
                c4d.gui.MessageDialog('fatal error, could not insert userdata.')
      

      What am I missing?

      Thanks in advance,
      Niklas

      UPDATE: Solution

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 25/11/2012 at 03:38, xxxxxxxx wrote:

        I also noticed that UserData created with this code is not accessible from XPresso, although I have
        added the following lines to the code:

                container.SetBool(c4d.DESC_INPORT, True)  
              container.SetBool(c4d.DESC_OUTPORT, True)
        

        Update: When I use the container of an existing UserData field and insert it as a new field, it works.. 😕

        -Nik

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 25/11/2012 at 08:14, xxxxxxxx wrote:

          Nevermind, I figured it out. 🙂

              def add_shader_pressed(self, op) :  
                name = c4d.gui.RenameDialog('Shader Field')  
                if not name:  
                    return  
            
                accept_shaders = c4d.BaseContainer()  
                accept_shaders.SetString(c4d.Xbase, "")  
            
                container = c4d.GetCustomDataTypeDefault(c4d.DTYPE_BASELISTLINK)  
                container.SetString(c4d.DESC_NAME, name)  
                container.SetLong(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_TEXBOX)  
            
                op.AddUserData(container)
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post