Currently this code creates an empty at a defined position and have used parent to get an object, in this case a cube to be in that position. However the newly created cube states its position as the origin rather than its actual position. How would I get the cube to display its actual position which would be the same as the empty?

import bpy
from mathutils import Matrix, Vector

context = bpy.context
scale = 0.01 

x, y, z, l, m, n, p, q, r = -500, 200, 1000, 1, 0, 0, 0, 0, -1

y_axis = Vector((l, m, n))
z_axis = Vector((p, q, r))

x_axis = y_axis.cross(z_axis).normalized()

M = Matrix((x_axis, y_axis, z_axis)).transposed()

M = M.to_4x4()

M.translation = scale * Vector((x, y, z))

print(x_axis, y_axis, z_axis)
mt = context.object
mt.empty_display_type = 'ARROWS'
empty = bpy.context.object
mt.matrix_world = M

cube = bpy.context.object
cube.parent = empty
  • 3
    $\begingroup$ Please ask only one question per post to make your question useful for others too... Please read: blender.stackexchange.com/help/how-to-ask $\endgroup$
    – brockmann
    Apr 30, 2020 at 9:57
  • 1
    $\begingroup$ How to create an empty without using ops (allows to don't rely on the object in context in your case): blender.stackexchange.com/questions/51290/… $\endgroup$
    – brockmann
    Apr 30, 2020 at 10:00
  • 2
    $\begingroup$ I'll edit the other question out $\endgroup$
    – newblender
    Apr 30, 2020 at 10:01
  • 1
    $\begingroup$ Why not using the matrix again? my_cube.matrix_world.translation? Don't get your question... $\endgroup$
    – brockmann
    Apr 30, 2020 at 10:11
  • $\begingroup$ A little confused as to what that non bpy.ops does, the use of adding an empty in the right place showing an axis system was useful to indicate the positioning of an object if it were placed there $\endgroup$
    – newblender
    Apr 30, 2020 at 10:13


Browse other questions tagged or ask your own question.