Maya Python - Parenting a Shape Node under a Transform Node

Hello everyone
I am writting a litte script in python in order to create an node based Ik -> Fk snap.
But I am running into an issue, I don’t know how to parent the shape node of my controler under the transform node of my joint. (left picture) I usually do it with this mel command ‘parent -s -r’
However I want to do it with python, I tried this command
‘mc.parent(Ctrlname, Jntname, shape=True, relative=True)’
But the result is not what I expect (right picture)techartist

Could someone help me with this issue ?

Maybe try setting the “add” flag to True instead of relative? This is what I usually use:
cmds.parent(ctrl, joint, add = True, shape = True)

Hi Luca ! It might not working because, i think, you are selecting 2 transforms. What u need is to select one shape, then one transform.

Try this maybe:
(select controler first, new parent in second)

import maya.cmds as mc

sel=mc.ls(sl=True)
shp=mc.listRelatives(sel[0], s=True)[0]
mc.parent(shp, sel[1], r=True, s=True)

Thank you all, it was indeed the fact that I was selecting the transform node and not the shape one.
:smiley:

1 Like

I hope this was helpful ! Don’t hesitate if you need anything to understand :smiley: