Solved Assignment Grouped

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

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

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

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

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

This post is deleted!

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