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
    • 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 get Redshift material assignments

    Cinema 4D SDK
    python
    2
    4
    729
    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.
    • orestiskonO
      orestiskon
      last edited by orestiskon

      Hello,
      I'm trying to get the material assignments for Redshift materials but I'm getting inconsistent results.

      The code is:

      material = doc.GetFirstMaterial()
      while material:
          assignment_list = material[c4d.ID_MATERIALASSIGNMENTS]
          print (material.GetName(), assignment_list.GetObjectCount())
          material = material.GetNext()
      

      Initially the assignment list shows the correct number of objects. But as soon as you interact the material, e.g. select it or rename it, then it shows 1 extra number of objects:

      c5a89d40-cb50-4584-9760-64480691f3a6-image.png

      Not sure how should I get the correct assignment list consistently, does anyone have any ideas?

      Here is an example file for convenience:
      reshift_isolate.c4d

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        Hi Orestis,

        This look like a bug that only happens with the old Redshift materials. Standard and the NodeMaterials are not affected by this issue. The problem is that the number come back to 1 or 0 if you save the file and re-open it so you can't always remove one form GetObjectCount.

        The only workaround that i have for you is to check if there is a "None" object in the list.
        I'm asking the devs if i missed anything and i will come back if i have more information.

        import c4d
        #Welcome to the world of Python
        
        
        def main():
            material = doc.GetFirstMaterial()
            while material:
                assignment_list = material[c4d.ID_MATERIALASSIGNMENTS]
                nb = assignment_list.GetObjectCount()
        
                numberOfChild = 0
                for x in range(0, nb):
                    obj = assignment_list.ObjectFromIndex(doc, x)
                    if obj is not None:
                        numberOfChild += 1
                print (material.GetName(), nb, numberOfChild)
        
                material = material.GetNext()
            print("")
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • orestiskonO
          orestiskon
          last edited by

          Thanks @m_magalhaes for looking it up, and writing a workaround, much appreciated!

          1 Reply Last reply Reply Quote 0
          • ManuelM
            Manuel
            last edited by

            hi,

            I got some feedback from the devs. The function ObjectFromIndex have a parameter to define the document. That mean the list can contain material tags from a different document. The "problem" is that ObjectFromIndex return the number of tags in the list, and not only the number of tags in the list that are present in the current document. Old Redshift materials have a mechanism to optimized and avoid rendering the preview thumbnail on the attribut manager when it is not necessary. That mechanism renders the material on a different document. That is why the entry on the list is "None" because the tag is not present in the document passed to the function ObjectFromIndex.

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

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