Showing posts with label Maya. Show all posts
Showing posts with label Maya. Show all posts

Thursday, March 24, 2011

Source order in Maya

Source order in maya is a bit more complex .... (Edit: and it makes me totally confused!!!)

First up - if you have set system based environment variables to wherever your maya installation resides, -which is normally done by the maya installer when your installation goes as intended- then maya finds the following folder containing MEL scripts in this order:

- program-folder: print(`getenv "MAYA_LOCATION"`+"/scripts/*");

- user script-directory: print( `internalVar -userAppDir`+"scripts");

- maya version specific script-directory: print( `internalVar -userScriptDir`);

although the may-version specific scripts-folder gets sourced last i prefer to put my scripts in the second location, because i don't need to copy any scripts to any new directory when another maya-version comes out- this directory gets sourced by them all!

so there's really no need to specifically source a scripts like that, unless of course you want to RUN the script on maya-startup!

that's something competely different, though!

it is considered good practice however not to run scripts by simply sourcing them. that has to do with the automatic sourcing process described above: every script in those folders get sourced on maya startup- make no mistake about that! so, better do it like this:

eval( "source ""+`internalVar -uad` + "scripts/nicescript.mel"") ;

and if this were a shelfbutton, or if you wanted to run it on startup, you would add the call to the function as well:

nicescript();

in early versions of maya your version of the 'source' command worked like you typed it; nowadays 'source' often fails for reasons that escape me right now, but with 'eval' i never had these problems!

!

Tuesday, February 15, 2011

Comprehensive Renamer: Maya Rename Script

Comprehensive Renamer: Maya Rename Script


Download Here (CreativeCrash)


One more rename script for Maya, written in mel, I'am trying to make it as feature rich as possible, so all requests are welcome.


Copyright (C) 2011 Dushyant Kumar Kashyap
MEL script for MAYA 8.0+
File: comprehensiveRenamer.mel
Desc: This is a simple mel script that allows the user to rename multiple Objects.
With lots-n-lots of options.
Author: Dushyant Kumar Kashyap (dushyantk@gmail.com)


Usages:  Just Source Script, it will call the required procedure automatically.



   

Tuesday, February 8, 2011

Save Incremental Version



Here's a small code to save an Incremental version of your maya file, so basically, no need to go to Save-As-> type the Name Again, just Copy the code in a MEL Shelf button: and every-time you need make an Incremental save, hit that Button.
  1. global proc incrementalSave()
  2. {
  3. string $f=`file -q -sn`; // get file name
  4. string $ft[]=`file -q -typ`; // file type (mayaAscii, etc.)

  5. if ($f!="")
  6. {

  7. // * extracting base filename (path/basename) and version number *

  8. string $n[],$ext="";

  9. if (tokenize($f,".",$n)) $ext=$n[size($n)-1];
  10. if (size($n)>1) $f=substring($f,1, size($f)-size($ext)-1 );
  11. if ($ext!="") $ext=("."+$ext);

  12. int $x=0, $m=1, $v=0, $d=0, $w=1;

  13. while($x==0)
  14. {
  15. string $e=substring($f,size($f),size($f)); // last character (as string)

  16. if (gmatch($e,"[0-9]")) // last character was a number?
  17. {
  18. $v+=($m*(int)$e);
  19. $m*=10;
  20. $d++; // (count number of digits)
  21. $f=substring($f,1,size($f)-1); // chop last character
  22. }
  23. else $x=1;
  24. }

  25. // * renaming current file (with incremented version number) *

  26. $v++; // increment version number
  27. string $vs=("000000000"+(string)$v);

  28. if ($d<1) $d=2; if ($d>8) $d=8;

  29. $vs=substring($vs,size($vs)-$d+1,size($vs));

  30. $f=($f+$vs+$ext);

  31. if (`confirmDialog -t "Save [+]" -m ("Save Scene As '"+$f+"' ?") -b "Ok" -b "Cancel" -cb "Cancel" -ds "Cancel"`!="Cancel")
  32. {
  33. file -rename $f;

  34. if (`file -q -ex $f`)
  35. {
  36. if (`confirmDialog -t "File Already Exists" -m ("Overwrite already existing file '"+$f+"'?") -b "Yes" -b "No" -cb "No" -ds "No"`!="Yes")
  37. $w=0;
  38. }

  39. if ($w)
  40. {
  41. //FileMenu_SaveItem;
  42. warning("projMan: Saving File...");
  43. evalEcho("file -save");
  44. addRecentFile($f,$ft[0]); // add to the recent files list
  45. }
  46. }
  47. }
  48. else projectViewer SaveAs;
  49. }
  50. incrementalSave;

Friday, January 21, 2011

Photo Metric Light Setup 0.1.2 (maya script)

Ok, so here’s what I’ve come-up with recently, This script can be used, to generate a simple Photo Metric Light Setup.

Download Here (CreativeCrash)

It works 100% accurate only if there’s no Other Area Light in the Scene.
This limitation is due to the fact that I am still working on fetching th newly created areaLight-name in a variable. (THIS IS FIXED ;)

Rest all works fine I guess, just source the script and it’ll create a setup for you. I’ll try to enhance it with UI and other stuff as and when I get time. Please check if I’ve left anything else.

EDIT: January 22, 2011: I’ve done changes to make it work everytime-and-everywhere with Existing Lights (with Maya 2011+ ). So everything's perfect now.

And if CreativeCrash ditches you, check this link: http://area.autodesk.com/forum/autodesk-maya/mel/photometric-light-creation/

EDIT: January 24, 2011:
(1) When it creates the light, the “Illuminates by default” option is unchecked, so the light is not active, This is fixed now.
(2) It creates a new mia_exposure_simple node each time the button is pressed. It should first check and see if an expsure node already exists on a camera and if so, not create a new one. Fixed.
(3) It should have been mia_exposure_photographic node instead of mia_exposure_simple. That's fixed too.


EDIT: January 31, 2011:
now this scripts connects mia_exposure_photographic to all cameras in Scene/


And CreativeCrash link is working perfectly. Finally they approved the file ;)

Monday, October 11, 2010

MEL: Time Kill


So, you are sitting in the studio, and nothing-as-such is assigned to you, or may be you just do not wish to move that stupid mouse for some time and take a break, but want to look like working darn hard:

Here's a small script for you...

  1. int $amount = 0;

  2. progressWindow
  3. -title "Initializing..."
  4. -progress $amount
  5. -status "Preview: 0%"
  6. -isInterruptable true;

  7. while (true) {

  8. // Check if the dialog has been cancelled
  9. if ( `progressWindow -query -isCancelled` ) break;

  10. // Check if end condition has been reached
  11. if ( `progressWindow -query -progress` >= 100 ) break;

  12. $amount += 1;

  13. progressWindow -edit
  14. -progress $amount
  15. -status ("Preview: "+$amount+"%");

  16. pause -seconds 3;
  17. }

  18. progressWindow -endProgress;

Put it in a shelf button. When executed, it'll create a DUMB progress windw, which does nothing but wait for time specified to complete it's function and go off. You can change "strings" in line number 4, 6, 21 according your needs. To play with time: change variable $amount increment and `pause` at line number 17 and 23 respectively.

P.S. Hope my employers don't go through this ;)

Wednesday, October 6, 2010

Operator Precedence in MEL:


This Image shows order of operator precedence in MEL. Operator in same row has equal precedence. Left most operator is evaluated first, if a statement has more then one operators of equal precedence. Something we generally don't care of, then can't figure out why things are messing up.