4
$\begingroup$

I tried this code that I found in the net in order to print the location of the camera in each frame of the animation.

import bpy

camera=bpy.data.objects['Camera']
sce = bpy.context.scene

for f in range(sce.frame_start, sce.frame_end+1):
    sce.frame_set(f)
    print("Frame %i" % f)
    print(camera.location)

After execution I get a fix location while the animation is fine.

I get like this:

<Vector (-35.4940, -2.9554, 5.3437)>
Frame 41
<Vector (-35.4940, -2.9554, 5.3437)>
Frame 42
<Vector (-35.4940, -2.9554, 5.3437)>
Frame 43
<Vector (-35.4940, -2.9554, 5.3437)>
Frame 44
<Vector (-35.4940, -2.9554, 5.3437)>
Frame 45
<Vector (-35.4940, -2.9554, 5.3437)>
Frame 46
<Vector (-35.4940, -2.9554, 5.3437)>
Frame 47
<Vector (-35.4940, -2.9554, 5.3437)>
Frame 48
<Vector (-35.4940, -2.9554, 5.3437)>
Frame 49
<Vector (-35.4940, -2.9554, 5.3437)>
Frame 50
<Vector (-35.4940, -2.9554, 5.3437)>`

How can I rectify the code ?

I have tried also the code given in this discussion :

How can I get the location of an object at each keyframe?

but it doesn't work. I get the following error :

AttributeError: 'NoneType' object has no attribute 'action'

What is the problem?

Thank you

$\endgroup$
9
  • $\begingroup$ What is the desired output format of the position data that you want? $\endgroup$ Commented Jul 3, 2015 at 16:10
  • $\begingroup$ The code from @gandalf3's answer in the linked question works just fine $\endgroup$ Commented Jul 3, 2015 at 16:17
  • $\begingroup$ The code does not work fine, the camera moves but positions printed are the same! $\endgroup$
    – mariem
    Commented Jul 3, 2015 at 16:37
  • 1
    $\begingroup$ the reason is that you are using constraints not a real animation $\endgroup$
    – Chebhou
    Commented Jul 3, 2015 at 17:12
  • 1
    $\begingroup$ Yes, I replace the code by the following : obj = bpy.context.scene.objects['Camera'] loc,rot,scale = obj.matrix_world.decompose() and it is OK ! Thank you for you contribution $\endgroup$
    – mariem
    Commented Jul 5, 2015 at 7:01

0

Browse other questions tagged .