About Me

Thursday, January 26, 2012

ReferenceQuery Madness!

If you're managing references in Maya and coding functions around it you'll know that the reference commands and query commands available to you are very limited. But here's a kicker that I found yesterday that to me, makes absolutely no sense what-so-ever!
So we all know how flaky the referenceEdit list is, but here's a bit of logic for you that we didn't realize until one of our tools started playing around.

Simple test, make a sphere in a fresh scene and save it, then reference it back into a new scene. Now make a cube and parentConstraint the referenced sphere to it. Now look at the referenceEdits, you should see this:

All well and good. So you'd think that if you queried the refEdits that's exactly what you'd get right? No
cmds.referenceQuery('SphereRN', successfulEdits=True, failedEdits=False, es=True) 
#Result:
[u'parent -s -r "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1" "|Sphere:pSphere1"',
 u'connectAttr "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintTranslateX" "|Sphere:pSphere1.translateX"',
 u'connectAttr "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintTranslateY" "|Sphere:pSphere1.translateY"',
 u'connectAttr "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintTranslateZ" "|Sphere:pSphere1.translateZ"',
 u'connectAttr "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintRotateX" "|Sphere:pSphere1.rotateX"',
 u'connectAttr "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintRotateY" "|Sphere:pSphere1.rotateY"',
 u'connectAttr "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintRotateZ" "|Sphere:pSphere1.rotateZ"',
 u'connectAttr "|Sphere:pSphere1.rotateOrder" "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintRotateOrder"',
 u'connectAttr "|Sphere:pSphere1.parentInverseMatrix" "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintParentInverseMatrix"',
 u'connectAttr "|Sphere:pSphere1.rotatePivot" "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintRotatePivot"',
 u'connectAttr "|Sphere:pSphere1.rotatePivotTranslate" "|SphereRNfosterParent1|Sphere:pSphere1_parentConstraint1.constraintRotateTranslate"']
So when you use the default query calls you actually get the edits back as if the refNode was in an unloaded state, note the connections to the fosterParent which would get created if I actually did unload the reference! Why, why the hell would you want the default option to return the data in an format that was currently invalid.

So there is a way round it, you use the 'liveEdits' flag. All good right, NO, the liveEdit flag returns the data WITHOUT THE DAG PATH! Short names, who the hell returns short names in any code blocks.
cmds.referenceQuery('SphereRN', successfulEdits=True, failedEdits=False, es=True, le=True)
Rant over, gotta go find a way round this now!

Mark