from datetime import datetime
from c4d.modules import mograph as mo
def is_cloner_active(cloner):
cloner[c4d.ID_BASEOBJECT_GENERATOR_FLAG] and
cloner[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] != c4d.OBJECT_OFF and
cloner[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] != c4d.OBJECT_OFF
def extract_color_from_material(mat):
"""Extract RGB color from supported material types."""
# Octane Diffuse or Universal Material
if mat_type in (1029501, 1029988):
color = mat[1001] # primary param
if color is None or not isinstance(color, c4d.Vector):
color = mat[1002] # fallback for GUI-visible color
if isinstance(color, c4d.Vector):
return tuple(int(min(max(c, 0.0), 1.0) * 255) for c in (color.x, color.y, color.z))
elif mat_type == c4d.Mmaterial:
color = mat[c4d.MATERIAL_COLOR_COLOR]
if isinstance(color, c4d.Vector):
return tuple(int(min(max(c, 0.0), 1.0) * 255) for c in (color.x, color.y, color.z))
def get_material_color(obj):
"""Use first polygon-selection material if present, else fall back to first available material."""
if not tag.CheckType(c4d.Ttexture):
mat = tag[c4d.TEXTURETAG_MATERIAL]
# Save first valid material as fallback
# If material has a polygon selection, use it
if tag[c4d.TEXTURETAG_RESTRICTION]:
return extract_color_from_material(mat)
# If no polygon selections found, use fallback
return extract_color_from_material(fallback_mat)
export_path = r"H:\My Drive\02_Projects\00_Prospective Projects\SPR_Yanbu\01_C4D"
timestamp = now.strftime("%Y%m%d_%H%M")
filename = f"cloner_export_{timestamp}.csv"
output_file = os.path.join(export_path, filename)
doc = c4d.documents.GetActiveDocument()
if op.CheckType(1018544): # Cloner
find_cloners(op.GetDown())
find_cloners(doc.GetFirstObject())
with open(output_file, 'w', newline='') as file:
writer = csv.writer(file)
"ClonerName", "CloneIndex", "ModelName",
"ScaleX", "ScaleY", "ScaleZ",
"ColorR", "ColorG", "ColorB"
if not is_cloner_active(cloner):
print(f"Skipping inactive cloner: {cloner.GetName()}")
mo_data = mo.GeGetMoData(cloner)
count = mo_data.GetCount()
matrices = mo_data.GetArray(c4d.MODATA_MATRIX)
child_count = len(children)
rot = c4d.utils.MatrixToHPB(mat)
c4d.utils.RadToDeg(rot.x),
c4d.utils.RadToDeg(rot.y),
c4d.utils.RadToDeg(rot.z)
model_obj = children[ref_id]
model_name = model_obj.GetName()
r, g, b = get_material_color(model_obj)
cloner.GetName(), i, model_name,
rot_deg.x, rot_deg.y, rot_deg.z,
scale.x, scale.y, scale.z,
c4d.gui.MessageDialog(f"CSV exported to:\n{output_file}")