# Access elements of matrix(vectors and Euler angles) in Animation nodes using script node

I would like to know to access individual elements of a matrix or matrices from Matrix/Matrix list input in the script node. Then I can perform some operations(experimentation) on those elements and then send them to output as a Matrix/Matrix list. I would like to do similar with Euler angles and Vectors. I am very new to programming and have searched this forum and coudn't find anything to do with this with regards to animation nodes.

## 1 Answer

Here are some examples for creating and decomposing each type:

Vector and Vector list

from mathutils import Vector

# create Vector
x = 1
y = 2
z = 3
new_vector = Vector((x,y,z))

# extract individual elements
x_element = new_vector.x # new_vector
y_element = new_vector.y # new_vector
z_element = new_vector.z # new_vector

# create AN vector list
new_vector_list = Vector3DList()

# append element to vector List
new_vector_list.append(new_vector)

# get element from vector List
first_element = new_vector_list

# get first element's x value
first_vector_x = new_vector_list.x


Euler and Euler list

from math import radians
from mathutils import Euler

# create Euler
x = radians(30)
y = radians(45)
z = radians(60)
new_euler = Euler((x,y,z)) # Euler((x,y,z),"XYZ")

# extract individual elements
x_element = new_euler.x # new_euler
y_element = new_euler.y # new_euler
z_element = new_euler.z # new_euler

# create AN euler List
new_euler_list = EulerList()

# append element to euler List
new_euler_list.append(new_euler)

# get element from euler List
first_element = new_euler_list

# get first element's x value
first_element_x = new_euler_list.x


Matrix and Matrix list

from mathutils import Matrix, Euler, Vector

# create matrix
location = Vector((0,0,0))
rotation = Euler((0,0,0))
scale = Vector((0,0,0))
new_matrix = AN.utils.math.composeMatrix(location, rotation, scale)

# extract location
extracted_loc = new_matrix.to_translation()

# extract rotation
extracted_rot = new_matrix.to_euler()

# extract scale
extracted_scale = new_matrix.to_scale()

# create AN matrix list
new_matrix_list = Matrix4x4List()

# append element to matrix list
new_matrix_list.append(new_matrix)

# get element from matrix list
first_element = new_matrix_list

# get first element's location
first_element_location = new_matrix_list.to_translation()

# get first element's x location
first_element_location = new_matrix_list.to_translation().x

# get raw matrix element
matrix_first_element = new_matrix_list


I suggest you to look at blender api documentation for more information.

• Thankyou for nice comprehensive answer. I just discovered the mathutils page about an hour and was in process of working it out. What other python functions like append should I look at that will be useful to manipulate, sort or search the lists. – Richard Bruno Jul 31 '20 at 17:52