# How to position the default blender cube given coordinates, direction Z vector and direction Y vector using python?

New to blender and python here,

Given the following:

Coordinates (X,Y,Z) = (-100,100,1000) and Direction Z vector = (1,0,0) and Direction Y vector = (0,0,-1) where angle between direction vectors is 90 deg

How would I position the default cube in blender there using python?

• It is a little hard to understand the expected workflow here, could you add a little more detail ? Apr 27, 2020 at 12:00
• Wondering if it is possible to have an add on in blender which will load sources using the above list array into correct positions and rotations like lighttools software. Apr 27, 2020 at 12:08
• Ok so you have a csv or excel file with transforms data, and you want to map these values to light objects transforms inside blender, is this correct ? Apr 27, 2020 at 12:31
• Yes, I believe so Apr 27, 2020 at 12:34
• Please use text to explain the data rather than image. Blender uses python. See stackoverflow.com (or other python sites, or search here for "[python] csv") re how to import csv or excel etc. Yes it is possible to make an addon. Suggest edit the question with the python to read the data. (or not) Add an example of one empty placed to match data line. As the question stands at the moment, to answer (other than "yes it's doable") requires teaching file I/O as well as the blender part. Please consider condensing question to just the how to position empty from data .. Apr 28, 2020 at 8:56

make a 3 x 3 rotation matrix with X, Y and Z axis as columns. Blender matrices are in rows, so will transpose rows to columns. The X axis is Y.cross(Z).

Make the matrix a 4x4 transform matrix and set its translation to coordinate

Note Added a scale factor so location 1000 -> 10. To avoid clipping. Set to 1 or remove.

import bpy
from mathutils import Matrix, Vector

context = bpy.context
scale = 0.01 # 1000 is a long way away

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

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

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))

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


#test