0
$\begingroup$

I have a cube.

The cube's Z rotation is 45 degrees.

If I press G X X, I can move the object along its local X axis.

How can I do this with a Python script?

$\endgroup$

1 Answer 1

3
$\begingroup$

I found the answer here.

  import bpy
  from mathutils import Vector, Matrix

  ...

  trans_local = Vector((0.0, 32.0, 0.0))
  trans_world = obj.matrix_world.to_3x3() * trans_local
  obj.matrix_world.translation += trans_world
$\endgroup$
4
  • $\begingroup$ or simply obj.location += Vector( (32, 0, 0) ) $\endgroup$
    – lemon
    Sep 3, 2016 at 6:38
  • $\begingroup$ @lemon - That's giving me a much different result. Are you sure that that works for local translation? $\endgroup$ Sep 3, 2016 at 19:32
  • $\begingroup$ You are right : I have badly read the question $\endgroup$
    – lemon
    Sep 4, 2016 at 5:46
  • 1
    $\begingroup$ > Blender 2.8: Use @instead of * for the matrix multiplication. $\endgroup$
    – Benedikt
    Jul 12, 2020 at 11:15

You must log in to answer this question.

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