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

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

aws357
Posts: 0
Joined: Wed Sep 21, 2005 4:59 pm

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

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

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.

ldo
Posts: 0
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand
Simply assign the new matrix to a matrix attribute of a Python object.

mb
Posts: 0
Joined: Mon Feb 22, 2010 10:20 am

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

aws357 wrote:...So if there is something that let me set the rotation matrix of an object directly, I would love to know about it.
The 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``````

aws357
Posts: 0
Joined: Wed Sep 21, 2005 4:59 pm
ldo wrote:Simply assign the new matrix to a matrix attribute of a Python object.
Thank you. I also got some help from a BA user TrumanBlending who kindly put some code snippet too.

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

ob = bpy.context.active_object

ob.matrix_world = mat

``````

aws357
Posts: 0
Joined: Wed Sep 21, 2005 4:59 pm

### 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:
aws357 wrote:...So if there is something that let me set the rotation matrix of an object directly, I would love to know about it.
The 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``````

ldo
Posts: 0
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand
See the to_4x4 or resize_4x4 methods here: http://www.blender.org/documentation/bl ... ils.Matrix.