Q: if statements in script for userSetup.mel?


#1

Hi all,

I’m trying to get a small script working via my userSetup.mel.

So far the following code works when starting Maya, giving me a dialog box with two buttons:

// This script warns you when you open a scene file that is not in PAL - 25fps

global proc FrameRateWarningPAL() {
string $currentfps = currentTimeUnitToFPS;
string $currentfpsName = currentUnit -q -time;
if ($currentfpsName!=“pal”) {
// create a confirm dialog with a yes and no button.
$response = confirmDialog -title "WARNING! Frame rate issue!!" -message ("This scene is not in 25 fps!! Reset Scene? (currently " + $currentfps + " fps)") -button "Yes" -button "No" -defaultButton "Yes" -cancelButton "No" -dismissString "No";

			}
				}

What I want is to check the response and start additional things, by adding this code:

// check response	  
	if( $response == "Yes" )
	{
		print("Scene reset to cm, 25fps, timeline and render 0-500 

");
}
else if( $response == “No” )
{
print("Really?? 30fps???
");

This will not work, probably due to the second if statement.

Can someone help me out here to solve this.
What I want in the end is to set some of the preferences via this startup script for scenes.

The response check works via the script editor in Maya, so it’s MEL correct.

cheers!

rob


#2

Please use the code tags to make your code better readable.

First: Your script will never work even if it is syntactically correct. The userSetup.mel will be executed only during the start of Maya. So if you open another scene, it will not help at all. So if you want to check your scene every time you create a new scene or open another one, you should try to use a scriptJob with your script.

Your code above is missing closing brackets, so I suppose you missed some lines during copy and paste.
You wrote that the popup appears, so can you tell us what exactly is not working for you and if there are error messages?


#3

Hi,

Thanks for responding, and sorry about the tags…

What I’m running in the userSetup.mel is this:


source "FrameRateWarningPAL.mel";
scriptJob -e "SceneOpened" "FrameRateWarningPAL;";

The script will run when Maya starts, but also runs when creating a new scene, or opening one.
If in any case a scene fps is other than 25, I will get the message box.

Got it working in the end:


// This script warns you when you open a scene file that is not in PAL - 25fps

global proc FrameRateWarningPAL()	{
    string $currentfps = `currentTimeUnitToFPS`;
    string $currentfpsName = `currentUnit -q -time`;
    if ($currentfpsName!="pal")	{
	// create a confirm dialog with a yes and no button.
	    $response = `confirmDialog -title "WARNING! Frame rate issue!!" 
		-message ("This scene is not in 25 fps!! Reset Scene? (currently " + $currentfps + " fps)")
		-button "Yes"
		-button "No"
		-defaultButton "Yes"
		-cancelButton "No"
		-dismissString "No"`;

// check button response	  

if($response == "Yes") {
	currentUnit -linear cm -angle degree -time pal;
	float $minTime = 1000.0;
	float $maxTime = 1500.0;
	playbackOptions -animationStartTime $minTime -minTime $minTime  -animationEndTime $maxTime -maxTime $maxTime -playbackSpeed 1;
	setAttr "defaultRenderGlobals.startFrame" 1000;
	setAttr "defaultRenderGlobals.endFrame" 1500;
	print("Woohoo! Succes!! :-) 
");
}
else {
	print("Phew! Didn't need it ;-) 
");
}
	}				  
	}

I think it was formatting of the code.

cheers!

rob