CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 03-23-2013, 08:41 AM   #1
cgiFlyBy
New Member
portfolio
David
Vancouver, Canada
 
Join Date: Mar 2013
Posts: 2
MEL Rendering script - global vatiables issue

Hi MEL experts!

Im working on a little script that is -when finished- supposed to provide a quick shelf button way of saving the current image from the renderviw to the disk.

But regardless of the main purpose and for convenience purposes I want to check if the script has been executed for the first time or if it has been executed before.
And that part is causing me a problem:

For some reason the script always says that it has already been executed before even when it hasn't been.

The code below is only the functionality that checks if it has been executed before:

Code:
//Getting a list of all existing declared global variables in Maya string $allGlobalVariables[] = `env`; //Finding out how many they are exactly to be able to go through all of them in the "for()" below int $size=size($allGlobalVariables); //Flag to mark if the script has been executed before int $scriptAlreadyExecutedOnce=0; //From here on: Check if the script has been executed before by checking if one global variable ($firstLauchGlobalVariableTrue) has already been created. (Which gets created only when the script has been run the first time in this Maya session). //For debugging reasons $i starts at 1 instead of 0. for($i=1;$i<=$size;$i++) { //write the name of the current `env` variable which is to be checked into the $currentlyCheckedVariable variable $currentlyCheckedVariable = $allGlobalVariables[($i-1)]; //Debugging //print("$i="+($i)+" | Loop run Nr. "+($i)+" | $size: "+$size+" | scriptAlreadyExecutedOnce= "+$scriptAlreadyExecutedOnce+" | Currently checked variable name: "+ $currentlyCheckedVariable +"\n"); if($currentlyCheckedVariable=="$firstLauchGlobalVariableTrue"){ print( "The Variable exists so the script has been launched once already! \n" ); $scriptAlreadyExecutedOnce=1; /*additional code for the actual functionality of this script will be placed here*/ } //Debugging //print("$i="+($i)+" | Loop run Nr. "+($i)+" | $size: "+$size+" | scriptAlreadyExecutedOnce= "+$scriptAlreadyExecutedOnce+" | Currently checked variable name: "+ $currentlyCheckedVariable +"\n"); //If we have reached the end of the "for()" and the script aparently has not been executed before then create the varaible now if($i==($size)&&$scriptAlreadyExecutedOnce==0){ print( "The Variable does not exist yet so the script has NOT been launched before! \n" ); //Declaring the variable now so that next time the script will be executed this "if" should not be accessed global int $firstLauchGlobalVariableTrue; /*additional code for the actual functionality of this script will be placed here*/ } }
 
Old 03-23-2013, 12:23 PM   #2
Nyro
Lurking
 
Nyro's Avatar
portfolio
A. D.
Vertex Slinger
Munich, Germany
 
Join Date: Dec 2006
Posts: 1,436
I'm having a hard time decoding your script, so I'll just offer an alternative:

Don't use global vars. Use optionVars.

Code:
if(!`optionVar -ex "isFirstRun"`) { // this is the first run optionVar -intValue "isFirstRun" 0; } else { // this isn't the first run // do something else }


The first time the script is run, the code above will notice that no such optionVar exists, and create it. Every following time the script is run after that, the optionVar will already exist and you can do whatever it is you want to do in that case.
Just make sure to choose a proper (that is, most probable unique) name for your optionvar.
 
Old 03-24-2013, 02:59 AM   #3
cgiFlyBy
New Member
portfolio
David
Vancouver, Canada
 
Join Date: Mar 2013
Posts: 2
Fantastic, thanks! I'll try it right away!
 
Old 03-24-2013, 02:59 AM   #4
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:52 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.