Object ignores Rotation from Matrix and more[Solved]

BoneFootprint.txt (722 Bytes)
I have the script which is meant to create an empty based on selected pose bone. The part starting from line 14 (“align empty to bone”) doesn’t work in 2.9 and higher, even if similar code worked in 2.79. More, it actually resets the empty’s location to zero

#align empty to bone
mat = bone.matrix
wmat = _me.matrix_world
bpy.context.active_object.matrix_world = wmat * mat#apply bone rotation to empty

2.80 Cheat Sheet for updating add-ons - Coding / Python Support - Blender Artists Community

Python API - Blender Developer Documentation

Matrix Multiplication

Matrix multiplication previously used *, scripts should now use @ for multiplication (per PEP 465). This applies to:

  • Vector * Vector
  • Quaternion * Vector
  • Matrix * Vector
  • Vector * Matrix
  • Matrix * Matrix

Note: In the future * will be used for element-wise multiplication

2.7x:

mat = Matrix()
vec = Vector()
result = mat * vec

2.8x:

mat = Matrix()
vec = Vector()
result = mat @ vec

Using the 2.7x syntax in 2.80 or later will result in this error:

TypeError: Element-wise multiplication: not supported between 'xxx' and 'yyy' types

In Place Matrix Multiplication

Note that mat_a *= mat_b did not change the original matrix, now in 2.8 it does (matching other types - Vector and Python lists for example).

Noting this since it could be a breaking change for scripts that relied on it creating a new matrix, especially if in cases where a matrix is passed as a function argument and changed to it aren’t expected.

1 Like

Worked perfectly, thanks!