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

    Assignment Grouped

    Cinema 4D SDK
    r21
    2
    6
    807
    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.
    • W
      WDP
      last edited by

      How can I use Python to select the sub-objects for a color assignment for grouped objects zero objects?

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hello @WDP,

        thank you for reaching out to us. Unfortunately your question is not clear for me. I assume you want to retrieve all children of a null object, so that you can add a material to them (to change their diffuse color)?

        It would be best if you could clarify your question. I have posted however an example for what seems likely to be your goal.

        Cheers,
        Ferdinand

        The result:
        5ac1ecc6-559e-495c-a2a2-452f94c0ff72-image.png
        The code:

        """Simple example for iterating over direct children and creating materials.
        
        To be run in the script manger.
        
        As discussed in:
            plugincafe.maxon.net/topic/13673/
        """
        
        import c4d
        import random
        
        
        def main():
            """Simple example for iterating over direct children and creating 
            materials.
            """
            # Bail when there is no object selected.
            if not isinstance(op, c4d.BaseObject):
                print ("Please select an object.")
                return
        
            # Bail when the active object has no children.
            if len(op.GetChildren()) == 0:
                print ("Object has no children.")
                return
        
            # Start an undo group.
            doc.StartUndo()
        
            # Iterate over all direct children of the selected object.
            for child in op.GetChildren():
                # Create a texture tag on the object and add an undo step for it.
                tag = child.MakeTag(c4d.Ttexture)
                doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, tag)
                # Create a new material with a random color.
                color = c4d.Vector(random.uniform(0, 1), 
                                   random.uniform(0, 1), 
                                   random.uniform(0, 1))
                material = c4d.BaseMaterial()
                material[c4d.MATERIAL_COLOR_COLOR] = color
                # Insert the material into the document, add an undo step and link the
                # material in the texture tag.
                doc.InsertMaterial(material)
                doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, material)
                tag[c4d.TEXTURETAG_MATERIAL] = material
        
             # Close the undo group.
            doc.EndUndo()
        
            c4d.EventAdd()
        
        
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • W
          WDP
          last edited by

          yes I would like to change the view color for the wireframe model

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @WDP
            last edited by

            Hello WDP,

            you mean the display color of an object?

            bd57cc19-7c3d-4554-be87-166ec09d0389-image.png

            It is just a parameter you can set as any other.

            import c4d
            
            def main():
                """Sets the display color of the selected object to red.
                """
                if op is None:
                    return
                
                # Set the "Display Color" parameter to "Custom"
                op[c4d.ID_BASEOBJECT_USECOLOR] = c4d.ID_BASEOBJECT_USECOLOR_ALWAYS
                # And set the "Color" parameter to red.
                op[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(1, 0, 0)
                
                c4d.EventAdd()
            
            if __name__=='__main__':
                main()
            

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • W
              WDP
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • ferdinandF
                ferdinand
                last edited by

                Hello @wdp,

                without any further questions we will consider this topic as solved by Friday, December the 17th.

                Thank you for your understanding,
                Ferdinand

                MAXON SDK Specialist
                developers.maxon.net

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