World location with parent and/or CopyLocation?

There are two situations that are bothering me in my translation of scripts from 2.49 to 2.5:

A: I have two objects. Object A is parented to bone(!) B (a.k.a. A is the child of B). I need to print out the WORLD location of object A, but I keep getting only the location relative to the parent.

B: I have two objects. Object A has a CopyLocation constraint, constraining it to bone(!) B’s location. I need to print the WORLD location of A, but I keep getting its location prior to the constraint (or when the constraint influence is 0).

I have been fighting this for days now. I expected to just use the parent_clear(type=“CLEAR_KEEP_TRANSFORM”) to make object A drop the parent without dropping the changed location, which makes its location WORLD rather than based on the parent. It works when done manually, but the python code doesn’t work, it just clears the parent and sends object A back to its location from before the parenting!

Please help :spin::frowning:

Hi,

I’m having a similar problem concerning the constraint problem, however for the first problem I would suggest adding the parrents world position to the childs relative position

This would be a rather cheap hack and there should be a way to directly retrieve this from blender, it should work though.

I tried, but if the parent is turned, the child is in a different spot without its (parent-relative) coordinates changing. And it would take some heavy math to account for parent rotation :frowning:

loc = object.matrix.translation_part()

I feel a sudden urge to worship you in some fashion :eek: Other than thanking you for saving my *ss, may I ask where exactly that code is found in the current API?

Here and here

Okay, I am getting very weird results here…

The script:

mo=bpy.data.scenes[“Scene”].objects[“Cube”]
ta=bpy.data.scenes[“Scene”].objects[“Armature”]
mo.parent=ta
loc=mo.matrix.translation_part()
print(loc)

When I run it, the matrix it prints out is 0,0,0
If I do nothing and run it again, THEN I get the actual location of ‘mo’! I need to run the script once for mo to get parented, and then again for Blender to actually realize that it is parented and give me the right location? Seriously, all I do is press the Run Script button twice, and I get a [0,0,0] matrix and then one with the right numbers. And I tried copying the above text multiple times into the script, I just get multiple [0,0,0] first time I run it, then multiple correct ones when I click again.

This is officially the weirdest malfunction I have ever seen in Blender… any idea what is going on??

EDIT: Hehe, my old nemesis returned… scene updates… I got it now. Thanks, you guys are pure gold!!!

I cleared Origin , Rotation , Scale , Location , at this point the empty.worldPosition should be exactly the same as cube.worldPosition with the exception of X axis. On X axis we should see 1 unit of difference. I’m getting wrong worldPosition on all 3 axis. What’s that about ? Press P and check console for log. Numbers should be same except for x.

Attachments

empty_position_001.blend (87.5 KB)