View Full Version : Query reference node name

12 December 2012, 12:43 PM
I want to create a script for quickly switching display between a reference and a proxy model.

You can do this manually from the reference editor by right clicking "proxy > reload proxy as" and Maya then calls on proxySwitch.

proxySwitch $nodeName
...performs the switch - but how do I get the nodeName of a ref and it's proxy model based on a selection in the outliner and/or viewport?

12 December 2012, 01:35 PM
string $object;

... assign target object to $object,
... e.g. via ls -sl

$referenceNode = `referenceQuery -rfn $object`;

12 December 2012, 02:16 PM
Thanks a bunch!

12 December 2012, 09:25 AM
There's just one problem
string $AIDS[] = `ls -sl`;
$referenceNode = `referenceQuery -rfn $AIDS`;

print $referenceNode;
Gets the name of the current active ref/proxy - not the associated ref/proxy.

proxySwitch requires the name of the associated ref/proxy (ie: the one you want to switch TO, not from) :(

12 December 2012, 09:57 AM
Yeah... uhm.. well I've never used a proxy before so I have not a clue, sorry :)

12 December 2012, 11:42 AM
Tried some of the flags to referenceNode and I still can't get the name of the associated proxy OR reference

12 December 2012, 11:50 AM
To be honest, I don't even understand what you are referring to when you say "association".

How many reference nodes are we talking about here? What other reference node would you need to query but the one your object belongs to?


Hang on, I think I was being a bit dense. I believe I now understand your problem. Give me a sec to create a test setup and investigate a solution ;)

12 December 2012, 12:22 PM
What I mean is that they are linked.
You add a proxy model to an already existing reference model - and they become link (or associated). Moving one of them, moves the other and so on.

I do not know "how" they are tied together though, as it doesn't seem to be a parent-child relationship.

12 December 2012, 01:00 PM

So I scoured proxyAdd.mel, proxySwitch.mel and proxyUtils.mel to see how it's done by Autodesk.
Long story short: I truly disliked all this stuff about connectionInfo and analyzing plugs, especially when we're dealing with frackin message attributes. Gave me a headache.

So here's my version, which is a bit simpler:

global proc proxyQuickSwitch() {
// get selected object
string $selection[] = `ls -sl`;
if(size($selection)) {
string $object = $selection[0];
// get current reference (original RN or proxyRN)
string $currentRN = `referenceQuery -rfn $object`;
// find the proxyManager attached to this reference
string $pmList[] = `listConnections -type "proxyManager" $currentRN`;
string $proxyManager = $pmList[0];
// get a list of referenceNodes managed by this PM
string $referenceNodes[] = `listConnections -type "reference" $proxyManager`;
// this will become the RN to switch to
string $targetRN;
// find the first RN in the list that ISN'T the current RN
// note that this only works reliably iff there is but a single proxy
for ($rn in $referenceNodes) {
if($rn != $currentRN) {
$targetRN = $rn;
// now switch to it
else {
warning "No objects selected";


This code only works properly if there is only 1 Proxy; if you look at the final for-loop, you'll see that it stops as soon as it finds a referenceNode that is not the current reference node. If you had the original Reference and then two proxies, the code might just switch from one proxy to another, but never to the original, etc.
I'll leave it to you to figure out some logic to workaround that issue ;)

12 December 2012, 01:59 PM
Awesome - you've helped out more than enough.
Thanks a bunch!

12 December 2012, 02:22 PM
no problemo

CGTalk Moderation
12 December 2012, 02:22 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.