I am trying to add add keyframes to an object from values in a csv file using python. It successfully reads the file and puts it into a list. However, it just gives me this error when adding the keyframes.
AttributeError: Writing to ID classes in this context is not allowed: Camera, Object datablock, error setting Object.<UNKNOWN>
This is the code that i have so far:
def draw(self, context):
results = []
layout = self.layout
obj = context.object
with open('record.txt', newline='') as inputfile:
for row in csv.reader(inputfile):
results.append(row)
line = 0
for x in results:
line += 1
if line > 2:
currentFrame = str(x)
xRot, yRot, zRot,_,_ = currentFrame.split(';')
xRot = xRot.replace("['", "")
print(xRot + " " + yRot + " " + zRot)
obj.rotation_euler[0] += float(xRot)
obj.keyframe_insert(data_path="rotation_euler", frame= float(line), index=0)
obj.rotation_euler[1] += float(yRot)
obj.keyframe_insert(data_path="rotation_euler", frame= float(line), index=1)
obj.rotation_euler[2] += float(zRot)
obj.keyframe_insert(data_path="rotation_euler", frame= float(line), index=2)
I would appreciate suggestions in how to solve this issue.
record.txtfile would let us give working solutions. $\endgroup$