This is the entire script: import c4d
import csv
import os
def find_export_object(root):
# Recursively search for the object named ‘Export’ in the hierarchy
if root is not None:
if root.GetName() == ‘Export’:
return root
for child in root.GetChildren():
found_object = find_export_object(child)
if found_object is not None:
return found_object
return None
def export_to_csv(csv_filename, points):
try:
# Open the CSV file in append mode
with open(csv_filename, ‘a’, newline=”) as csvfile:
csvwriter = csv.writer(csvfile)
# Loop through each point and write its coordinates
csvwriter.writerow([x, y, z])
print(f'Data appended to {csv_filename}')
def get_next_filename(base_path, base_filename):
version = 1
while True:
new_filename = f”{base_filename}_{version}.csv”
full_path = os.path.join(base_path, new_filename)
if not os.path.exists(full_path):
return full_path
version += 1
def main():
# Get the active document
doc = c4d.documents.GetActiveDocument()
if doc is None:
c4d.gui.MessageDialog(“No active document found.”)
return
# Find the object named 'Export'
export_object = find_export_object(doc.GetFirstObject())
if export_object is None:
c4d.gui.MessageDialog("Object named 'Export' not found in the scene.")
# Specify the CSV file directory
base_path = r'C:\Users\Chris\OneDrive\Desktop\Test'
# Manually set the frames per second (FPS)
# Get the next available filename before the frame loop
csv_filename = get_next_filename(base_path, base_filename)
# Determine the start and end frames
start_frame = int(doc.GetMinTime().GetFrame(fps))
end_frame = int(doc.GetMaxTime().GetFrame(fps))
for frame in range(start_frame, end_frame + 1):
doc.SetTime(c4d.BaseTime(frame, fps))
# Get the deformed state of the object
deformed_object = c4d.utils.SendModelingCommand(
command=c4d.MCOMMAND_CURRENTSTATETOOBJECT,
if deformed_object is not None:
# Get the points of the spline
points = deformed_object.GetAllPoints()
# Append the data to the CSV file for this frame
export_to_csv(csv_filename, points)
# Delete the temporary object after use
temp_doc = c4d.documents.BaseDocument()
temp_doc.InsertObject(deformed_object)
c4d.documents.KillDocument(temp_doc)
print("Export completed.")
if name == “main”:
main()