[Maya] Inconsistent PyMel behavior compared to CMDS and MEL

Hi,

I’m trying to change my constraint offset using the following code (i.e. PyMel):

constraint = pm.ls("IKLegFront1_R_parentConstraint1")[0]
constraint.target[0].attr("targetOffsetRotateY").set(130)

It gives me an error of

A child attribute of 'IKLegFront1_R_parentConstraint1.target[0]' is locked or connected and cannot be modified. # 

I can access it but I can’t modify it. The attribute is also not locked nor connected to anything else.

Interestingly, I ran the same command in CMDS and MEL and it works as expected.

CMDS

constraint = cmds.ls("IKLegFront1_R_parentConstraint1")[0]
cmds.setAttr(constraint + '.target[0].targetOffsetRotateY', 120)

MEL

setAttr "IKLegFront1_R_parentConstraint1.target[0].targetOffsetRotateY" 130;

May I ask what am I missing for the PyMel implementation?

I guess when you use setAttr() it knows how to interpret the attribute properly.

You can also do it in PyMEL and it works.

pm.setAttr(constraint + '.target[0].targetOffsetRotateY', 12)

But for setting the attribute directly in PyMEL, it is cast as a TdataCompound. I honestly don’t know what that implies. But you can do this, and pass it a pymel.core.datatypes.Vector or a list:

constraint.target[0].targetOffsetRotate.set([0, 120, 0])

1 Like

Thanks for the response.
Can confirm this works as expected.

RE: I honestly don’t know what that implies.
I guess this is one of those Maya quirks that we will never know hehe