PDA

View Full Version : Go to Anaglyph mode (python inside mel issues)


kAzIDamUI
02-14-2011, 09:51 PM
Hello everyone,

I'm currently working on a stereo job and those who've tried it already know that there is a lot of back and forth in the menus to enable and disable the different views, modes, etc.
Especially on the mac version of 2011... it gets pretty wonky...

so I'm building a couple of shelf buttons to help my team and I to save some precious time...

This one would be used pretty much all the time I guess...
The purpose is to look through the selected stereo pair and enable the anaglyph mode.
After getting the name and panel of my selected camera I've tried to copy the different commands Maya calls when it's loading the stereo options and enabling the anaglyph mode.


lookThru `ls -sl`;
string $came[] = `ls -sl`;
string $camT = $came[0];
string $currentPanel = `getPanel -withFocus`;
string $regex = "(scriptEditor)";
string $currentPanel = `substitute $regex $currentPanel "model"`;
python( "import maya.mel as mel" );
python( "TransferMELvar = maya.mel.eval(\"$camTpy=$camT\")" );
python( "TransferMELvar = maya.mel.eval(\"$currentPanelpy=$currentPanel\")" );
python( "mel.eval('stereoCameraSwitchToCamera $camTpy $currentPanelpy')" );
stereoCameraSwitchToCamera $camT $currentPanel;
python( "from maya.app.stereo import stereoCameraCustomPanel" );
python( "TransferMELvar = maya.mel.eval(\"$camTpy=$camT\")" );
python( "stereoCameraCustomPanel.switchToCamera($camTpy,\"StereoPanelEditor\")" );
findNewCurrentModelView;
python( "stereoCameraCustomPanel.stereoCameraViewCallback( \"StereoPanelEditor\", \"{'displayMode': 'anaglyph'}\" )" );


I think I'm in the right direction even though I'm a total noob...
but I can't manage to use variables the same way in mel in python (even more noobie in python).
Here's what I get :

stereoCameraCustomPanel.switchToCamera($camTpy,"StereoPanelEditor")
# Error: line 14: invalid syntax #

I know my code must be really barbarian...
Sorry and thank you for those who care to help.

NaughtyNathan
02-14-2011, 11:17 PM
a couple of things here Jean:
you don't use $ on python variables
you don't need to convert MEL vars to python
use string catenation to combine literal strings and variables
use 'single quotes' in python so you don't have to escape them in MEL strings

e.g.
desired (python) result:
stereoCameraCustomPanel.switchToCamera('someCamNode','StereoPanelEditor')in MEL:
string $MELVar = "someCamNode";
python ("stereoCameraCustomPanel.switchToCamera('" + $MELvar + "','StereoPanelEditor')");
I hope this makes some sense.. :)
:nathaN

kAzIDamUI
02-14-2011, 11:44 PM
Awesome, thanks a lot !
I've modified the script according to your notes and found the part that was breaking down the whole thing...

Now it's working. Thx again
:beer:


lookThru `ls -sl`;
string $came[] = `ls -sl`;
string $camT = $came[0];
string $currentPanel = `getPanel -withFocus`;
string $regex = "(scriptEditor)";
string $currentPanel = `substitute $regex $currentPanel "model"`;
python( "import maya.mel as mel" );
stereoCameraSwitchToCamera $camT $currentPanel;
python( "from maya.app.stereo import stereoCameraCustomPanel" );
python( "stereoCameraCustomPanel.switchToCamera('" + $camT + "',\"StereoPanelEditor\")" );
findNewCurrentModelView;
python( "stereoCameraCustomPanel.stereoCameraViewCallback( \"StereoPanelEditor\", \"{'displayMode': 'anaglyph'}\" )" );

CGTalk Moderation
02-14-2011, 11:44 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.