Why would adding a parent with Python make the child unmovable?

update:

As it turns out, it was because I scaled the child object to z = 0 - c.scale(1,1,0) - scaling to non-zero works just fine

I have a child called c and a parent called p.

I use Python to create a parent-child relation.

Either:

p.select = True
c.select = True
bpy.context.scene.objects.active = p
bpy.ops.object.parent_set(type="OBJECT")
p.select = False
c.select = False
bpy.ops.object.select_all(action='DESELECT')


or simply:

c.parent = p


The parent-child relationship is established, which I can confirm in the Outliner.

If I move p in the 3D View the child c will also move, however I cannot move c - it seems locked to it's position, however when I check the locks in the Properties Editor no locks are active. I can alter the location using the transform properties in the Properties Editor, but I can't move it using the mouse. I can scale and rotate as normal though.

Both p (an empty) and c (a text) is created in Python.

If I do the same manually - create the objects and set their parent relationship, I can move the child in the UI. This is the type of relationship I dream of (one where I can move :P ).

How can I add a parent relationship from Python that lets me move both the parent (with the child following) and the child (on its own) from the UI?

Further observations: The problem seems to be in the object creation process. No matter how I parent objects that are Python-created, I end up with not being able to move the child on it's own. I even tried to use the exact same code line that the UI uses to generate the object.

• I hope you don't mind my edit. Further information can be added to the question via editing - I think this makes it a bit easier for people reading it. – Martynas Žiemys Nov 9 '18 at 19:28
• That's great - it's actually what I ought to have done - if you wish to, you can delete these comments as well. They have no info-value :) – Acebone Nov 9 '18 at 19:55

This works fine:

import bpy

C = bpy.context
a = C.object
b = C.object
a.parent = b
a.matrix_parent_inverse = b.matrix_world.inverted()


As you can see:

There must be something wrong with the code you use for creating the objects. You should try removing the parenting part of your code and see if the code around it works fine.

• Indeed it does - thank you Martin. The trick seems to be: a.matrix_parent_inverse = b.matrix_world.inverted() but I'm not sure what's going on? Btw. the code around it works as expected – Acebone Nov 9 '18 at 19:48
• Seems to work without the line a.matrix_parent_inverse = b.matrix_world.inverted() That is only to keep the original transforms of the object that is parented. I am affraid I have no ideas why it might not work without seeing more of your code. I can not find a way to replicate the issue. – Martynas Žiemys Nov 9 '18 at 20:33
• Ok, I'm a newbie with blender :) The problem was that I scaled the text-object to (1,1,0) - which in real 3D of course is nonsense - I'm going to use it for video, so I don't care about the third D (in this case) import bpy C = bpy.context bpy.ops.object.text_add(location=(0, 0, 0)) a = C.object  a.scale = (1,1,0) bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 1)) b = C.object a.parent = b – Acebone Nov 9 '18 at 22:46
• not very clear - thing is - don't do a.scale(1,1,0) – Acebone Nov 9 '18 at 22:48
• Niewbie or not, that is still weird - an object scaled 0 in Z axis should still be movable. I don't think this is supposed to be like that. There might be a bug somewhere there. But then there are quite a few of those in Blender Python's API, it's not perfect. And I don't think it is possible for it to be. Luckily this will most likely not influence the result you are trying to reach. – Martynas Žiemys Nov 9 '18 at 23:43