So... I have a little problem, I have made a grid of objects made with Voronoi Fracture, and I'm trying to assign a material to each individual polygon from the fracture object. I can't see a way to assign a material based on the number index of a cloner/fracture object/voronoi object or create a list of selection tag on the voronoi fracture...
I wish that the index number could be a variable that we could use as a selection or tag! If anyone has an idea of how to tackle this issue, I would love to hear you out, this is what I have so far:
import c4d
def main():
# Get the active object, which should be a Voronoi Fracture object
fracture_obj = doc.GetActiveObject()
# Check if the object is a Voronoi Fracture object
if fracture_obj is None or not fracture_obj.CheckType(c4d.Ofracture):
raise RuntimeError("Please select a Voronoi Fracture object.")
# Access the children of the Voronoi Fracture object (these are the fractured pieces)
fracture_pieces = fracture_obj.GetChildren()
# Ensure there are fracture pieces
if not fracture_pieces:
raise RuntimeError("No fracture pieces found. Please ensure the Voronoi Fracture is applied to an object.")
# Loop through each fracture piece
for i, piece in enumerate(fracture_pieces):
# Create a unique polygon selection tag for each piece
selection_tag = piece.MakeTag(c4d.Tpolygonselection)
selection_tag.SetName(f"Piece_{i}_Selection")
# Select all polygons of this fracture piece
poly_selection = c4d.BaseSelect()
poly_count = piece.GetPolygonCount()
for poly_index in range(poly_count):
poly_selection.Select(poly_index)
# Assign the selection to the tag
selection_tag.SetBaseSelect(poly_selection)
# Refresh the scene to apply the changes
c4d.EventAdd()
# Execute the script
if __name__ == '__main__':```