The error message you’re encountering, “AttributeError: ‘c4d.BaseTag’ object has no attribute ‘GetAbsPos’,” indicates that the script is attempting to access a method (GetAbsPos) on an object that doesn’t support it. In this case, op refers to the Python tag itself, not the Matrix object it’s attached to. The method GetAbsPos() is applicable to objects, not tags.
To correct this, you need to reference the object to which the tag is attached, not the tag itself. In Cinema 4D, this can be done using op.GetObject(), which will return the object the tag is attached to.
Here’s the revised script:
# Get the object to which the Python tag is attached
matrix_object = op.GetObject()
# Check if the object is correctly referenced
print("Object not found")
# Get the current frame number
currentFrame = doc.GetTime().GetFrame(doc.GetFps())
# Retrieve the position of the object for testing
position = matrix_object.GetAbsPos()
# File path for saving data
filePath = f"H:/My Drive/02_Projects/41_SPTF_FCBNY Spotify/00_Research and Development/C4D/Sketching/231122 Write Values from C4D/Written/object_position_frame{currentFrame}.txt"
# Write the position data to the file
with open(filePath, "a") as file:
file.write(f"Frame {currentFrame} Position: {position}\n")
# Print a message for confirmation
print(f"Position data for frame {currentFrame} written to {filePath}")
This script now correctly references the object to which the Python tag is attached and retrieves its position. It then writes this position data to a file for each frame when the timeline is played.
This test should help confirm if basic data access and file writing are functioning correctly in your setup. If this works without errors, then the issue with your original script is likely specific to accessing MoGraph data, and not with the Python tag or file writing process.