Parent and Unparent in OpenMaya?

88 views
Skip to first unread message

João Victor

unread,
Mar 17, 2021, 4:20:41 PM3/17/21
to Python Programming for Autodesk Maya
Hi guys, could somebody help me in a doubt?

I am trying to parent B to A, then move A, then unparent B. But at the end of these operations, B can´t return to his original position, he must keeps where A brought him.
How can I do that in the API?

My current code is:

q1 = getMObject("A")
q2 = getMObject("B")

p = new_om.MFnDagNode(q1)
p.addChild(q2)

u = new_om.MDagModifier()

u.reparentNode(q2)   # here B returns to original position, thats the problem
u.doIt()

Thanks a lot!

tomas mikulak

unread,
Mar 17, 2021, 4:25:33 PM3/17/21
to python_in...@googlegroups.com
Hi,
I am not into API yet, but what if you also parented a locator under A with same position and rotation as B and after unparenting B just set it's transforms according to locator still under A
Bad?

tomas

st 17. 3. 2021 o 21:20 João Victor <joaovi...@gmail.com> napísal(a):
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/89a295a8-835c-4a23-8dd5-6bc0399d55e4n%40googlegroups.com.

João Victor

unread,
Mar 17, 2021, 4:32:14 PM3/17/21
to Python Programming for Autodesk Maya
thanks a lot for the suggestion Tomas!
but I can´t use CMDS for parenting the new "helper locator",  because I am looking for reduce the time of the loop.. and it have to be made about 30k times in the loop. For this reason I am trying to use the api instead of CMDS. :)

tomas mikulak

unread,
Mar 17, 2021, 4:35:16 PM3/17/21
to python_in...@googlegroups.com
and if you just use variable to save world matrix of parented B and after unparent just use data. Still guessing, don't know how slow it might be 

st 17. 3. 2021 o 21:32 João Victor <joaovi...@gmail.com> napísal(a):

João Victor

unread,
Mar 17, 2021, 5:00:54 PM3/17/21
to python_in...@googlegroups.com
Let me check if I got..
If I:
1) store the matrix of the B ("ORIGINAL_B_pos") (before parenting to A)
2) parent B to A
3) move A (which will bring B to another place, to "NEW_B_pos")
4) unparent B (so B will go back to "ORIGINAL_B_pos" )
5) apply matrix in B (after this 5th step, B will go to "NEW_B_pos" ?)

You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/PTE_CUQsO_c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAEUzAD3br5mf1XrFQb7kRqYBH9RyqHvuMHnG3F5nLJ1-R5YuFQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages