4
$\begingroup$

Is there any method to get location of an object which has "follow path" and "track to" constraints?

import bpy
scene = bpy.context.scene
scene.objects['Cube'].location[0]
scene.objects['Cube'].location[1]
scene.objects['Cube'].location[2]

The code above gives me constant location of an object, relative to the followed path I suppose

I would like to get global location instead, just like in case of an object with no constraints.

Any suggestions will be appreciated :)

$\endgroup$

2 Answers 2

3
$\begingroup$
scene.objects['Cube'].matrix_world[0][3]

scene.objects['Cube'].matrix_world[1][3]

scene.objects['Cube'].matrix_world[2][3]

bpy.context.active_object.matrix_world[0][3]

bpy.context.active_object.matrix_world[1][3]

bpy.context.active_object.matrix_world[2][3]
$\endgroup$
6
  • $\begingroup$ it may be necessary to call a scene.update() before reading the values of matrix_world -- if you notice that the values don't change even though the UI does display changed values. $\endgroup$
    – zeffii
    Commented Sep 8, 2015 at 15:09
  • 1
    $\begingroup$ see: blender.stackexchange.com/questions/27667/… $\endgroup$
    – zeffii
    Commented Sep 8, 2015 at 15:11
  • $\begingroup$ Thank you atomicbezierslinger, ".matrix_world" do the job for the object location :) And how about the rotation? Could it be also read from this matrix? I've made some test, but I got not obvious results and I couldn't figure out which matrix elements correspond to rotation. $\endgroup$
    – Alice
    Commented Sep 9, 2015 at 10:42
  • $\begingroup$ Did you have any success? I am still not clear on that. $\endgroup$ Commented Sep 9, 2015 at 16:21
  • 1
    $\begingroup$ There should be a decompose() function on the matrix that lets you determine the location, scale, and orientation. $\endgroup$
    – Mutant Bob
    Commented Dec 7, 2015 at 15:39
-1
$\begingroup$

Once you've set your constraints, you can see the object's location changing by dragging the time cursor in the timeline. The 'Python' way to do it is to use the function :

scene.frame_set(i_frame)

Then, you can use object.location to access the 3 Vector containing the location of the object. The indices of the location vector are simply the X, Y and Z components of the location (no link to the frames of the path). The same way, you can access to the rotation of the object using one of these :

object.rotation_euler
object.rotation_quaternion
object.rotation_axis_angle

Usually, the Euler reresentation of the rotation of the object is preferred. Both the location and rotation of the object are defined globally.

$\endgroup$
1
  • $\begingroup$ I think this is where my problem is -while I'm draging the time cursor in the timeline, the values of x,y,z location of the object stay 0, although I can observe that the object is moving along the path in the viewport. This problem doesn't occur in case of the object with movement defined by simple keyframing the object location values. However I really need to have the "follow path" constraint. I use Blender 2.75. Could you please check if there is different result in your Blender instalation? $\endgroup$
    – Alice
    Commented Sep 7, 2015 at 13:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .