parent child relation in python API 2.5


I’m currently working on a custom export script for blender 2.5 projects. But I have troubles with parent child relations. As far as I understood, every object has it’s local space. this space remains intact when adding to a parent. So when setting the child’s coordinates to (0,0,0) doesn’t necessarily mean it’s at the parents origin, but at the childs space origin, that is relative to the parent. That makes sense.

But how do I retrieve the local offset with python? there is object.matrix.location_part() but that returns the absolute coordinates. (parent local space + child local space)

I hope you understand what I mean. Hard to explain…

thank you

Right after posting I got a little closer to the solution. By substracting the parent matrix from the child matrix, I get the local offset. (parent.matrix-child.matrix) I’ll try that.

This works for offset, but not for the scale, a scale of 1 is 0 afterwards, which is mathematically correct but not as easy to use.

I still don’t know how to get the offset with a script. But this post helped getting the matrix partially right: blender forums Obtaining the Local Transformation Matrix

This script resets the child’s origin, so it matches the parents origin. So there is no offset any more.

bl_addon_info = {
    'name': 'reset origin of child object',
    'author': 'Philip Whitfield (underdoeg)',
    'version': '0.1',
    'blender': (2, 5, 2),
    'url': '',
    'description': 'Sets the origin of child objects to parent\'s origin',
    'category': 'Operations'}

# Operator
class ResetChildOrigin(bpy.types.Operator):
    bl_label = "Reset Child Origin"

    def execute(self, context):
        objs = context.selected_objects
        #loop the objects
        for obj in objs:
            if obj.parent != None:
                #get the offset for later
                parMat = obj.parent.matrix 
                locMat = obj.matrix
                mat = parMat.copy().invert()*locMat
                #now clear origin and location
                obj.selected = True
                #move back to original location
                obj.location = mat.translation_part()
                #deselect to finish up
                obj.selected = False
        #little cleanup, restore original selection
        for obj in objs:
            obj.selected = True

def register():

def unregister():

if __name__ == "__main__":

Although nobody seems to be really interested in this topic, I post my solution here. I had to extend the above script, now it works for animation as well. You can download it at