Problems trying to wwitch between Maya reference proxies in python/pymel

I’m trying to do a proxy switch on referenced files in Maya.
I can achieve this in MEL but I’m finding no love in trying to achieve the same with python/pymel.

Closest thing I’ve found is the proxyManager node, but I’m clueless about how to perform the switch.
Has anyone done this before or have any ideas they can offer me?

MEL works fine:
proxySwitch firstFileRN;

Pymel and cmds give me no luck:
eval(“proxySwitch firstFileRN”)

…I’m sure I’m missing something, but I’ve had no ideas after searching through the pymel, python and Maya node documentation.

You might want to just look through ProxyActivate.mel and find the actual sequence of steps and do them in python directly, instead of mel-evalling.

But did you mean maya.mel.eval? eval is also a python keyword, you’ll get gibberish if you haven’t got maya.mel.eval for the line you put up.

Thanks!
I didn’t realise eval was a keyword - I’ll have a hunt through proxyActivate and try an import as for the maya.mel.eval .
Will post any results I get from looking into that.

I opted to dive into proxyActivate.mel to get a better understanding of what Maya is actually doing there.

Seems like the proxyActivate looks at the active proxy’s proxyManager node to get its .activeProxy connection - and uses that connection to get the active proxy’s RN.
It unloads that, connects the .activeProxy message to the plug of the reference we’re now going to make active instead and loads in that new guy.

Turned out to be more straightforward than I’d assumed, something I’ve been able to redo in pymel without much difficulty. The core functionality is working beautifully, now I just need to script it up to work in the pipe.

Theodox, you are a star. Thank you.

I use this in MEL (no calls to any of Autodesk’s external MEL scripts):

global proc proxyQuickSwitch()
{
    // get selected objects (and count)
    string $selection[] = `ls -sl`;	
	int $objCount  = `size($selection)`; 		
	
	// For each object
	for ($i = 0; $i < $objCount; $i++)
	{
		if(size($selection))
		{
			string $object = $selection[$i];
			
			// get current reference OR proxy
			string $targetRN;
			string $currentRN = `referenceQuery -rfn $object`;
			
			// find the proxyManager
			string $pmList[] = `listConnections -type "proxyManager" $currentRN`;
			string $proxyManager = $pmList[0];
			
			// get a list of reference nodes managed by this PM
			string $referenceNodes[] = `listConnections -type "reference" $proxyManager`;
			
			// find the first RN in the list that ISN'T the current RN (only works if there is a single proxy)
			for ($rn in $referenceNodes)
			{
				if($rn != $currentRN)
				{
					$targetRN = $rn;
					break;
				}
			}
			
			// switch to it
			proxySwitch($targetRN);
		} else {
			warning "No objects selected";
		}
	}
}

proxyQuickSwitch;

And as you can see, it works on multiple references/proxies by going through them with a for loop. Extremely handy!
Hope that helps.

Thanks Nightshade. Managed to cobble together a solution in pymel before your post – looks pretty similar to the approach you’ve taken but nice to get to see a MEL solution to it.