MEL scripts


#321

Connects a bokeh node with distance and parents one locator to the camera.


global proc bokeh(){
	string $sel[] = `ls -sl`;
	float $childPos[] = `xform -q -t $sel[0]`;
	float $camPos[] = `xform -q -t $sel[1]`;
	string $cShape[] = `listRelatives -s $sel[1]`;
	string $bokehNode = ($sel[1]+"_bokeh");
	string $ddShape = ($cShape[0]+"_ddm");
 
	string $dd = `distanceDimension -sp $childPos[0] $childPos[1] $childPos[2] -ep $camPos[0]
	$camPos[1] $camPos[2]`; 
	rename $dd $ddShape;
 
	string $con[] = `listConnections $ddShape`;
	parent $con[1] $sel[1];
	string $bokeh = `mrCreateCustomNode -asUtility "" mia_lens_bokeh`;
	rename $bokeh $bokehNode;
	connectAttr -f ($bokehNode+".message") ($cShape[0]+".miLensShader");
	connectAttr -f ($ddShape+".distance") ($bokehNode+".plane");
}
bokeh();

 


#322

Not sure how many people are going to use something like this, but I thought I’d share just in case.

Considering the network for the mip_ shaders (in this case for compositing) is ridiculous, this helps it along. This network is based on what’s seen here:

http://forums.cgsociety.org/showthread.php?f=87&t=541718&page=2&pp=15&highlight=mip_cameramap

Select camera and run.


global proc setMipBG(){
	string $sel[] = `ls -sl`;
	string $selShapes[] = `listRelatives -f $sel[0]`;
	string $camPath = $selShapes[0];
 
	// GLOBAL NODES //
	string $emptyAlpha = `mrCreateCustomNode -asUtility "" mib_color_alpha`;
	setAttr ($emptyAlpha+".factor") 0;
 
	// CAMERA NODES //
	string $cEnv = `mrCreateCustomNode -asUtility "" mip_rayswitch_environment`;
	string $cHdr = `mrCreateCustomNode -asUtility "" mip_mirrorball`;
	setAttr ($cHdr+".degamma") 2.2;
 
	// MATERIAL NODES //
	string $mEnv = `mrCreateCustomNode -asUtility "" mip_rayswitch_environment`;
	string $mCmap = `mrCreateCustomNode -asUtility "" mip_cameramap`;
	setAttr ($mCmap+".degamma") 2.2;
	string $ms = `mrCreateCustomNode -asShader "" mip_matteshadow`;
 
	// CAMERA CONNECTIONS //
	connectAttr -f ($cEnv+".message") ($camPath+".miEnvironmentShader");
	connectAttr -f ($emptyAlpha+".outValue") ($cEnv+".background");
	connectAttr -f ($emptyAlpha+".outValueA") ($cEnv+".backgroundA");
	connectAttr -f ($cHdr+".outValue") ($cEnv+".environment");
	connectAttr -f ($cHdr+".outValueA") ($cEnv+".environmentA");
 
	// MATERIAL CONNECTIONS //
	connectAttr($emptyAlpha+".outValue") ($mEnv+".background");
	connectAttr($emptyAlpha+".outValueA") ($mEnv+".backgroundA");
	connectAttr($mCmap+".outValue") ($mEnv+".environment");
	connectAttr($mCmap+".outValueA") ($mEnv+".environmentA");
 
	connectAttr ($mEnv+".outValue") ($ms+".background");
	connectAttr ($mEnv+".outValueA") ($ms+".backgroundA");
}
 

Feel free to tear it up, but for me I run this script when I’m ready to start the rendering-for-compositing home stretch. Gets the nodes connected up (sans textures/shading groups) and I can apply it to different cameras/export with ease.


#323

Hi folks, I’m new here, just thought I’d post a neat little script to change the value of a checkbox according to whether or not it was checked before (i.e. in a window that was later closed)

window testWindow;
  columnLayout;
  
  checkBox 
  	-onCommand $onValue
  	-offCommand $offValue
  	-value $testValue
  	testBox;
  
  showWindow testWindow;
  
  int $testValue = `checkBox -q -v testBox`;
  string $onValue = "$testValue = 1";
  string $offValue = "$testValue = 0";

It’s nothing special but I think it’s pretty cool :thumbsup:


#324

Hi Camaro!

If you thought thats cool. Check this out:
you can have that with an optionVar much cleaner and straightforward!

window;
	columnLayout;
		checkBox
			-v (`optionVar -q myTextCheckBoxOptionVar`)
			-cc ("optionVar -iv myTextCheckBoxOptionVar #1");
showWindow;

plus: with the secret #1 placeholder you automatically put in the current value of the control. Works with almost all controls :thumbsup:


#325

Hey thanks, I’ll have to test that out! :bowdown:


#326

Ok, I have to say, I went through the command reference, and I don’t understand it one bit. Could someone explain how to use optionVar in detail?


#327

He Camaro!

optionVar is the one command Maya uses itself to save all the preferences. And you can utilize it yourself very easily! Its clean, fast and the best: persistent!

Even if the optionVar-name does not exist

optionVar -q "yourOptionVarName";

returns a proper integer 0.
So you can use it in your checkBox and create/toggle the optionVar on -changeCommand with:

optionVar -intValue "yourOptionVarName" $yourIntValue;

for instance.

in the same style you can have floats and strings saved as well.
What else is unclear?


#328

So you use the -intValue flag when its a 1 or 0 like a checkbox?


#329

exactly.
The -value flag awaits an integer. So you can feed it with anything that returns one.

checkBox -v 1;
checkBox -v $myIntVar;
checkBox -v ((int) $aFloatVariable);
checkBox -v (`optionVar -q myTextCheckBoxOptionVar`);

IF “myTextCheckBoxOptionVar” is defined as an -intValue optionVar of course…


#330

Any reason MEL can’t interpret a decimal value, such as (35 / 100)? This could screw up my whole script if I can’t get something simple like that to work. All I need is a decimal/float value.

My only other alternative is to take a value like 35 and convert it to .35 somehow.


#331

Try:

float $result = (35.0 / 100.0)

#332

or in a call you can always cast variables to a certain type like I wrote in the example: ((int) $floatVar) or ((float) $intVar1 / $intVar2)


#333

Is there any way to make it so you can specify the shape of a button other than a square/box? Or perhaps use an image as a button somehow (not a symbolButton, mind you)?

I’m trying to emulate this:

http://www.paolodominici.com/products/zvgui/#media

But obviously not as advanced, as I’m pretty sure he uses Python. I’m just trying to make it so the user can select parts of a rig from an image without simple boxes for the buttons.

Sorry for turning this into a question thread, I just don’t want to clog up the main forum with a bunch of different threads/questions.


#334

the command iconTextButton should work for you, it’ll still be square but you can use an image instead.

u can also make the image your using transparent by making the background of your .bmp 0 254 0 rgb colors and indexing it to the first slot in your color index.


#335

The functional shape of Mayas buttons will always be rectangular. Maybe you go pyQT? Don’t know of its capability now but should be huge ^^

At least you can have mouseover-images utilising the shelfButton images.

Thats exactly what its there for!! :]


#336

sorry for helping to move this thread out of track. Some more helpful little melScripts:

I often animate lots of nodes. This simply copys the animation of 1 object to all other selected ones, no selection order to care about:

{
	string $sel[] = `ls -sl`;
	// get animcurves from selection and route back to animated transforms
	string $animated[] = stringArrayRemoveDuplicates(listConnections(`keyframe -q -name`));
	
	if (!size($animated))
		error"no animated obj!";
	if (size($animated) > 1)
		error"can only copy from 1 animated obj!";
	// so if there is only 1 animated obj we can go on:
	// remove the animated one from the selection array
	$sel = stringArrayRemove($animated,$sel);
	// copy from anmated, paste on all others:
	copyKey $animated[0];
	pasteKey $sel;
}

#337

actually i want to know abt autosuspension ,means i want to do suspension in my car.in scene my car is passing through hilly area,so the road has many up , downs & i dont want to creat suspension manually.i i want to do it through expression,is there any way to do my work throuh expression or script.plz help me.i m creating my demo real.


#338

Hi ranjeetthecgartist!
What about posting your question in a new topic in the main thread?
This here is about posting/sharing and discussing existing scripts.


#339

I made a little time saver for those cases that you want a reflection to appear at a specific place on your object. (see the screenshot and the render)

This script creates two straight lines, grouped together. You position the main one (the one with less expressions on it) pointing to the camera and the tip of the two lines should be on the surface.

EPCurveTool;
 curve -d 3 -p 0.00509434 0 0.251053 -p 0.333085 0 0.256715 -p 0.661075 0 0.262377 -p 0.989066 0 0.268039 -k 0 -k 0 -k 0 -k 1 -k 1 -k 1 ;
 select -r curve1.cv[0] ;
 move 0 0 0 ;
 select -r curve1.cv[3] ;
 move 6 0 0 ;
 select -r curve1.cv[2] ;
 move 4 0 0 ;
 select -r curve1.cv[1] ;
 move 2 0 0 ;
 select -cl  ;
 select -r curve1.cv[0:3] ;
 hilite curve1.cv[0:3] ;
 select -d curve1.cv[0:3] ;
 hilite -u curve1 ;
 select -r curve1 ;
 duplicate -rr;
 // Result: curve2 //
 rotate -r -ws 0 -140.506888 0 ;
 rotate -r -ws 0 -39.628589 0 ;
 setAttr "curve2.rotateY" 180;
 FreezeTransformations;
 makeIdentity -apply true -t 1 -r 1 -s 1 -n 2 -jointOrient;
 select -r curve1 ;
 FreezeTransformations;
 makeIdentity -apply true -t 1 -r 1 -s 1 -n 2 -jointOrient;
 expressionEditor EE "curve1" "translateX";
 expression -s "curve1.scaleY = 1\r"  -o curve1 -ae 1 -uc all ;
 // Result: expression1 // 
 expression -s "curve1.scaleZ = 1"  -o curve1 -ae 1 -uc all ;
 // Result: expression2 // 
 select -r curve2 ;
 expression -s "curve2.scaleX = curve1.scaleX"  -o curve2 -ae 1 -uc all ;
 // Result: expression3 // 
 expression -s "curve2.scaleY = curve2.scaleY"  -o curve2 -ae 1 -uc all ;
 // Result: expression4 // 
 expression -s "curve2.scaleZ = curve1.scaleZ"  -o curve2 -ae 1 -uc all ;
 // Result: expression5 // 
 expression -e -s "curve2.scaleY = curve1.scaleY"  -o curve2 -ae 1 -uc all  expression4;
 // Result: expression4 // 
 expression -s "curve2.rotateX = curve1.rotateX"  -o curve2 -ae 1 -uc all ;
 // Result: expression6 // 
 expression -s "curve2.rotateY = -curve1.rotateY"  -o curve2 -ae 1 -uc all ;
 // Result: expression7 // 
 expression -s "curve2.rotateZ = curve1.rotateZ"  -o curve2 -ae 1 -uc all ;
 // Result: expression8 //  
 
 select -r curve1 curve2 ;
 group; xform -os -piv 0 0 0;

#340

I’m new here so I really appreciate it