How can I use Python to select the sub-objects for a color assignment for grouped objects zero objects?
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.
"""Simple example for iterating over direct children and creating materials.
To be run in the script manger.
As discussed in:
"""Simple example for iterating over direct children and creating
# Bail when there is no object selected.
if not isinstance(op, c4d.BaseObject):
print ("Please select an object.")
# Bail when the active object has no children.
if len(op.GetChildren()) == 0:
print ("Object has no children.")
# Start an undo group.
# 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)
# Create a new material with a random color.
color = c4d.Vector(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.
tag[c4d.TEXTURETAG_MATERIAL] = material
# Close the undo group.
if __name__ == '__main__':
yes I would like to change the view color for the wireframe model
you mean the display color of an object?
It is just a parameter you can set as any other.
"""Sets the display color of the selected object to red.
if op is None:
# 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)