Code for global co-ords / unparenting
import math import poser for i in range(0, 60): yscale = 1 scene = poser.Scene() scene.SetFrame(i) rope_target = scene.Actor("box_1") rope = scene.Actor("cyl_1") rope.SetParentActor(rope_target) xdiff = abs(rope_target.ParameterByCode(poser.kParmCodeXTRAN).Value() - rope.ParameterByCode(poser.kParmCodeXTRAN).Value()) ydiff = abs(rope_target.ParameterByCode(poser.kParmCodeYTRAN).Value() - rope.ParameterByCode(poser.kParmCodeYTRAN).Value()) zdiff = abs(rope_target.ParameterByCode(poser.kParmCodeZTRAN).Value() - rope.ParameterByCode(poser.kParmCodeZTRAN).Value()) yscale = (xdiff * xdiff) + (ydiff * ydiff) + (zdiff * zdiff) yscale = math.sqrt(yscale) yscale = yscale * 10 rope_target.ParameterByCode(poser.kParmCodeYSCALE).SetValue(yscale)
This is a code I'm trying to create where I need to find the co-ordinates of two objects in order to calculate the difference between two objects (a straight line rope and the target) and accordingly scale the rope. It works fine on unparented objects but I'm running into issues with parented objects due to (I'm assuming) the use of local co-ordinates. Is there a way to either:
Get the global co-ordinates of an object
Or Unparent an object then reparent it. This is the method I've attempted (in line 9, however it is returning this error: AttributeError: 'Actor' object has no attribute 'SetParentActor'
Any help would be appreciated
I think the method you need is SetParent rather than SetParentActor. If I've read the documentation correctly, SetParentActor is for figure parenting and your aim is to parent an object.
That said, I can't see anywhere in your code that does the unparenting. Line 9 is trying to parent to box_1. Unparenting an object is equivalent to parenting it to UNIVERSE, and that method should work to give you global coordinates. It's how I do it manually, anyway.
It would be simpler to un-parent the object before executing the frame loop, then re-parent it afterwards; which is probably best done at frame 1, by the way.
I'll have a play with this later on. It sounds like a useful thing to be able to do.
Ah yes, I was running into some errors whilst using I had "UNIVERSE" as the set parent target (?), so I changed it to an object I knew the definite internal name of it.
The set parent function now works, but I can't use it with UNIVERSE, as it returns this error:
poser.error: Parent argument is not an actor object
Poser API is stupid and doesn't do the obvious things, like if you pass the name of an actor, it should look up the actor automatically. It does not.
You have to pass an actor to SetParent, and so you should call scene.Actor("UNIVERSE") for the stupid thing.
I suggest you rehearse your steps interactively within the Python Shell. Like this:
Not only will you get to try things more quickly, you also get hover tips that fill you in on spelling things, like when you didn't see the function was SetParent. In this window, as soon as you type "a.Set" you're going to see all the names of the setter functions in a popup.
@bagginsbill Ah, ok. My combined lack of knowledge with poser python and python on its own makes for an... interesting experience :).
The script does now work, I think there were some issues in the looping or something. But yea, thanks for all the help :)