I am trying to get one of my older python scripts to work in Blender 2.62.

In the old script, I would use setMatrix to apply the rotations I get from an external file containing a 3x3 matrix (mocap kind of...).

Since the changes in the python API, I have not been able to find back this function.

Any hint is welcome, I searched the forum, but maybe I missed the info...

To makes thing more confusing, there is still the function to generate a rotation matrix in mathutils :

# create a rotation matrix

mat_rot = mathutils.Matrix.Rotation(math.radians(45.0), 4, 'X')

But for the life of me I could not find where this new rotation could be applied to an object in blender... All there is now is Euler and Quaternion. I could use conversions with to_euler or to_quaternion, but there is always somekind of tradeoff in these conversions... So if there is something that let me set the rotation matrix of an object directly, I would love to know about it.

## What is the equivalent of setMatrix in blender 2.62?

**Moderators:** jesterKing, stiv

### Re: What is the equivalent of setMatrix in blender 2.62?

Theaws357 wrote:...So if there is something that let me set the rotation matrix of an object directly, I would love to know about it.

*matrix_world*attribute (method?) can be used to assign a 4x4 transform matrix to an object. I did not find any method for direct access to the rotation part of the matrix, so if your original matrix is 3x3 it must be copied to a 4x4 equivalent.

For exemple:

Code: Select all

```
import bpy
from mathutils import Matrix
obj = bpy.data.objects['Cube']
# the original matrix is 3x3:
M3x3 = Matrix([(0.2519, 0.0000, 0.0000),
(0.0000, 0.2519, 0.0000),
(0.0000, 0.0000, 0.2519)])
# Create a 4x4 copy:
M4x4 = M3x3.to_4x4()
# Assign 4x4 matrix to the object:
obj.matrix_world = M4x4
```

Thank you. I also got some help from a BA user TrumanBlending who kindly put some code snippet too.ldo wrote:Simply assign the new matrix to a matrix attribute of a Python object.

I'm putting this here in case someone stumble on this post and has the same question.

Code: Select all

```
import bpy
from mathutils import Matrix
from math import radians
ob = bpy.context.active_object
mat = Matrix.Rotation(radians(45), 4, 'X')
ob.matrix_world = mat
```

My WIP blog :

http://digitaldraw.wordpress.com/

http://digitaldraw.wordpress.com/

### Re: What is the equivalent of setMatrix in blender 2.62?

Thanks for the answer, I was wondering how to make a 4x4 matrix from those 3x3 matrices I received. This should make for cleaner code in my script.

mb wrote:Theaws357 wrote:...So if there is something that let me set the rotation matrix of an object directly, I would love to know about it.matrix_worldattribute (method?) can be used to assign a 4x4 transform matrix to an object. I did not find any method for direct access to the rotation part of the matrix, so if your original matrix is 3x3 it must be copied to a 4x4 equivalent.

For exemple:Code: Select all

`import bpy from mathutils import Matrix obj = bpy.data.objects['Cube'] # the original matrix is 3x3: M3x3 = Matrix([(0.2519, 0.0000, 0.0000), (0.0000, 0.2519, 0.0000), (0.0000, 0.0000, 0.2519)]) # Create a 4x4 copy: M4x4 = M3x3.to_4x4() # Assign 4x4 matrix to the object: obj.matrix_world = M4x4`

My WIP blog :

http://digitaldraw.wordpress.com/

http://digitaldraw.wordpress.com/

See the to_4x4 or resize_4x4 methods here: http://www.blender.org/documentation/bl ... ils.Matrix.