I was looking at this article related to detecting changes in an object's position: https://s-nako.work/2020/12/how-to-detect-object-moving-in-blender-addon/

But, I want to expand this to detect any changes to the object's transformation. One option would be to separately track position, rotation, and scale. I will implement that until I find a better solution, but I know that there has to BE a better solution.

It's easy enough to get the selected object's transformation, but how do I store that value in a property? I did find this related question: Which of Blender's bpy.props properties can store a Matrix?

I also found an article which covers creating a custom matrix property: https://b3d.interplanety.org/en/custom-property/

These look like two very different approaches. I'm not sure which of these I should be trying to understand, or how to apply either solution to my case.

EDIT: I suppose I should mention that I tried simply using the following:

def register():
    bpy.types.Object.before_matrix = bpy.props.FloatVectorProperty(
        name = "before_matrix",
        subtype = "MATRIX"

def unregister():
    del bpy.types.Object.before_matrix


def obj_init( scene ):

    if hasattr( bpy.context, "object" ):
        print( "object {} transform changed".format( bpy.context.object.name ) )
        bpy.context.object.before_matrix = bpy.context.object.matrix_local

since FloatVectorProperty has a "MATRIX" subtype, but this results in the following error:

bpy.context.object.before_matrix = bpy.context.object.matrix_local
ValueError: bpy_struct: item.attr = val: Object.before_matrix, matrix assign array with 1 dimensions


Actually it looks like Blender 3.0 makes this quite a bit simpler, as covered in https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Python_API:

Added multi-dimensional array support for bpy.props vector types (FloatVectorProperty, IntVectorProperty, BoolVectorProperty). (bc0a7d3fae).

Example that defines a 4x4 matrix property:

bpy.props.FloatVectorProperty(size=(4, 4), subtype='MATRIX')

@scurest: I haven't tested your solution, but I understand it and see how it would work, so have an upvote.

  • 3
    $\begingroup$ Pass size=16 to FloatVectorProperty to get a 4x4 matrix. To assign a matrix, turn the matrix into a list first: [x for col in matrix.col for x in col]. $\endgroup$
    – scurest
    Jan 26 at 23:23


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.