Im trying to export X & Y coordinates of certain object to file with this script I found years ago somewhere:
import bpy
def write_some_data(context, filepath, use_some_setting):
print("running write_some_data...")
camera = context.active_object
mw = camera.matrix_world
scene = context.scene
frame = scene.frame_start
f = open(filepath, 'w', encoding='utf-8')
while frame <= scene.frame_end:
scene.frame_set(frame)
x, y, z = mw.to_translation()
rx, ry, rz = mw.to_euler('XYZ')
f.write("%d" % frame)
f.write(", ")
f.write("%5.3f, %5.3f" % (x, y))
f.write("\n")
frame += 1
f.close()
return {'FINISHED'}
It almost works, but output looks like this:
0, 0.510, -0.370
1, 0.518, -0.190
2, 0.524, -0.010
3, 0.536, 0.177
4, 0.544, 0.365
5, 0.553, 0.548
6, 0.559, 0.730
7, 0.568, 0.912
8, 0.575, 1.094
9, 0.575, 1.283
10, 0.574, 1.471
My purpose is to save X & Y positions inside area of 512,512px (rendered 2D size) and output should have coordinates between 0 - 512px. I dont know python or scripting well, been looking for answer for couple of days now.