I’m using this code in Cinema 4dto read a csv file (containing an x,y,z coodinate of a series of points) and transfers this information to a matrix object:
import c4d
import csv
def main():
# Path to your CSV file
csv_file_path = ‘C:/Users/Chris/OneDrive/Desktop/Test/file_2.csv’
# Create an empty list to store the vectors
with open(csv_file_path, 'r') as csvfile:
csvreader = csv.reader(csvfile)
# Assuming the CSV has x, y, z coordinates in separate columns
x, y, z = map(float, row[:3])
points.append(c4d.Vector(x, y, z))
print(f"Error parsing row {row}: {e}")
# Check if any points were parsed
print("No valid points found in the CSV file.")
# Create a new Matrix object or get an existing one
matrix_obj = c4d.BaseObject(c4d.Omatrix)
# Transfer the points to the Matrix object
for i, point in enumerate(points):
# Create a new matrix for each point
# Add the matrix to the object
# Insert the Matrix object into the current document
doc.InsertObject(matrix_obj)
if name==‘main’:
main()
But I’m getting this error:
Error parsing row [”, ”, ”]: could not convert string to float: ”
Traceback (most recent call last):
File “scriptmanager”, line 49, in
File “scriptmanager”, line 33, in main
AttributeError: module ‘c4d’ has no attribute ‘Omatrix’