MEL scripts


#381

Thought I’d come and share some of the scripts that I’ve written that have made the long-term cut.

To be sourced and run via SGT_SGTweakWindow(). See video at creativecrash here.


/*
Object Tweaker v 0.3 by Steven E. Geer
* Selected objects are given random rotation, translation, or scale values in X, Y or Z.
* Modify at own risk.
* Contact: stevenegeer (at) gmail
*/
global proc SGT_executeTweak(){
	string $checkedAxes[];
	string $checkedDir[];
	string $empty[] = {""};
	string $flagged[];
	 
	$checkedAxes[0] = (`checkBoxGrp -query -value1 axesCheckGroup`) == 1 ? "X" : "";
	$checkedAxes[1] = (`checkBoxGrp -query -value2 axesCheckGroup`) == 1 ? "Y" : "";
	$checkedAxes[2] = (`checkBoxGrp -query -value3 axesCheckGroup`) == 1 ? "Z" : "";
	
	$checkedDir[0] = (`checkBoxGrp -query -value1 dirCheckGroup`) == 1 ? "-ro" : "";
	$checkedDir[1] = (`checkBoxGrp -query -value2 dirCheckGroup`) == 1 ? "-t" : "";
	$checkedDir[2] = (`checkBoxGrp -query -value3 dirCheckGroup`) == 1 ? "-s" : "";
	
	string $finalCtxArray[] = stringArrayRemove($empty, $checkedAxes);
	string $finalDirArray[] = stringArrayRemove($empty, $checkedDir);
	float $finalAmount = `floatSliderGrp -query -value amountSliderGroup`;
	float $multiplier = `floatSliderGrp -query -value multiplierGroup`;
	
	$flagged[0] = (`radioButtonGrp -q -select translatePositioning` == 1) ? "-r" : "-a";
	$flagged[1] = (`radioButtonGrp -q -select rotatePositioning` == 1) ? "-r" : "-a";
	$flagged[2] = (`radioButtonGrp -query -select spaceRadioGroup`) == 1 ? "-ws" : "-os";
	
	if((size($finalCtxArray) && size($finalDirArray)) != 0){ 
		SGT_tweak($checkedAxes, $finalAmount*$multiplier, $checkedDir, $flagged);
	}else{
		error("You must have at least one axis and one context selected.");
	}
}
global proc SGT_tweak(string $direction[], float $maxAmount, string $ctx[], string $flags[]){
	float $amount;
	int $i = 0;
	int $curObject = 0;
	string $sel[] = `ls -sl`;
	
	string $attr;
	if(size($sel) == 0){
		error("You must have at least one object selected.");
	}else{
		string $rValues[];
		string $tValues[];
		string $sValues[];
		
		int $isRot = 0;
		int $isTrans = 0;
		int $isScale = 0;
		int $pAmount = 0;
		
		progressWindow
			-title "Tweaking..."
			-progress $pAmount
			-status "Tweaking Objects "
			-isInterruptable true
			-min 0
			-max `size $sel`;
		
		for($object in $sel){ 
			
			float $startScale[] = `xform -r -q -s $object`;
			float $delta;
			
			if(`progressWindow -q -ic`) break;
			$curObject++;
			progressWindow -edit -status ($curObject+"/"+size($sel));
			progressWindow -edit -progress $curObject;
			 
			for($cx in $ctx){
				if($cx != ""){
					switch($cx){
						case "-ro":
							$delta = rand($maxAmount * -1, $maxAmount);
							for($i = 0; $i < 3; $i++){
								$rValues[$i] = ($direction[$i] == "" ? "0" : $delta + " ");
							}
							$isRot = 1;
						break;
						case "-s":
							$delta = rand( ($maxAmount*.1)*-1, $maxAmount*.1);
							for($i = 0; $i < 3; $i++){
								$sValues[$i] = ($direction[$i] == "" ? "0" : $startScale[$i] + ($delta) + " ");
							}
							$isScale = 1;
						break;
						case "-t":
							float $delta = rand( ($maxAmount/2)*-1, $maxAmount/2 );
							for($i = 0; $i < 3; $i++){										
								$tValues[$i] = ($direction[$i] == "" ? "0" : $delta + " ");
							}
							$isTrans = 1;
						break;
                   				}
           				}
			}
		//perform each move seperate
			if($isRot == 1){
				string $rn = stringArrayToString($rValues, " ");
				string $tok[];
				tokenizeList($rn, $tok);
				string $command = ("xform "+$flags[2]+" "+ $flags[1] +" -ro ");
				for($bar in $tok){
					$command += ($bar + " ");
				}
				$command += ($object);
				eval($command);
					}
			if($isTrans == 1){
				string $tn = stringArrayToString($tValues, " ");
				string $tok[];
				tokenizeList($tn, $tok);
				string $command = ("xform "+$flags[0]+" " + $flags[0] + " -t ");
				for($bar in $tok){
					$command += ($bar + " ");
				}
				$command += ($object);
				eval($command);
					}
			if($isScale == 1){
				string $sn = stringArrayToString($sValues, " ");
				string $tok[];
				tokenizeList($sn, $tok);
				string $command = ("xform "+$flags[2]+" -s ");
				for($bar in $tok){
					$command += ($bar + " ");
				}
				$command += ($object);
				eval($command);
			}
		clear $startScale;
		if($curObject == size($sel)) progressWindow -endProgress;
		}
	}
}
global proc SGT_SGTweakWindow(){
	if(`window -exists SGTweakerWindow`) deleteUI SGTweakerWindow;
	if(`windowPref -exists SGTweakerWindow`) windowPref -remove SGTweakerWindow;
	
	string $axes[] = {"X", "Y", "Z"};	
	string $context[] = {"r", "t", "s"};
		
	float $amount;

	string $tweakWindow = 
	`window -t "Tweak v 0.3" -s 0 -wh 400 230 -mnb true	SGTweakerWindow`;
	columnLayout -adj 1	columnContainer;
		separator -h 10;
		setParent columnContainer;
		rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5;
			text -l "Axes" -w 100;
		rowLayout -nc 1	-cw1 100;
			checkBoxGrp -ncb 3	-la3 "X" "Y" "Z" -va3 true true true -cw3 70 70 70 axesCheckGroup;
		setParent columnContainer;
		rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5;
			text -l "Context" -w 100;
		rowLayout -nc 1 -cw1 100;
			checkBoxGrp	-ncb 3 -la3 "Rotate" "Translate" "Scale" -va3 true false false -cw3 70 70 70 dirCheckGroup;
		setParent columnContainer;
		rowLayout -nc 2	-cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5;
			text -l "Tweak Amount" -w 100;
		rowLayout -nc 1	-cw1 100;
			floatSliderGrp	-f true	-min 0.0001	-max 5	-fmx 5 -fmn 0.0001 -pre 4 -v 1 amountSliderGroup;
		setParent columnContainer;
		rowLayout -nc 2	-cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5 multCol;
			text -l "Multiplier" -w 100;
		rowLayout -nc 1 -cw1 100 multiCol1;
			floatSliderGrp -f true -min .1 -max 5 -fmx 5 -v 1 -pre 1 multiplierGroup;
		setParent columnContainer;
		separator -height 20;
		setParent columnContainer;
		columnLayout -adj true -p columnContainer;
			frameLayout	-l "Flags" -cll 1 -pcc "int $winHeight = `window -q -h SGTweakerWindow`; window -e -h ($winHeight - 120) SGTweakerWindow;" -pec "int $winHeight = `window -q -h SGTweakerWindow`; window -e -h ($winHeight + 120) SGTweakerWindow;" -cl 1
			flagGroup;
			columnLayout -adj 1 
				localCol;
				rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5;
					text -l "Space" -w 100;
				rowLayout -nc 1 -cw1 100;
					radioButtonGrp -nrb 2 -sl 1	-la2 "World" "Object" spaceRadioGroup;
						
					setParent localCol;
				separator -h 20 -vis 1;
					setParent localCol;
				frameLayout -l "Context Positioning" -cll 0	-mh 10 -mw 0 -li 150 -bs "etchedOut" -h 80
					positionGroup;
					columnLayout posLocal;
					rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 1 "top" 5 -rat 2 "top" 5;
						text -l "Translate" -w 100;
					rowLayout -nc 1	-cw1 100;
						radioButtonGrp -nrb 2 -sl 1	-la2 "Relative" "Absolute" translatePositioning;
						setParent posLocal;
					rowLayout -nc 2	-cw2 130 120 -cl2 "right" "left" -rat 2 "top" 4;
						text -l "Rotate" -w 100;
					rowLayout -nc 2	-cw1 100;
						radioButtonGrp -nrb 2 -sl 1 -la2 "Relative" "Absolute"	rotatePositioning;
					setParent localCol;
		setParent columnContainer;
		separator -h 20;
		rowColumnLayout -nc 2 -cw 1 175 -cw 2 175 -cal 1 "center" -cal 1 "center" -co 1 "left" 40 -co 2 "left" 40 -w 400 bottomCol;
		button -w 200 -l "Apply" -c "SGT_executeTweak";
		button -w 200 -l "Close" -c "deleteUI SGTweakerWindow";
	
	showWindow $tweakWindow;
}

Simple snap A to B


global proc snapObject(){
	string $sel[] = `ls -sl`;
	if(size($sel) != 2){
		error("You must have only 2 objects selected.");
	}else{
		string $parent = $sel[1];
		string $child = $sel[0];

		float $parentCoord[] = `xform -q -ws -t $parent`;
		xform -ws -t $parentCoord[0] $parentCoord[1] $parentCoord[2] $child;
	}
}
snapObject();

And a script to attach a bokeh node to a camera based on a selected object (Select Object, then Camera and run)


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 $cameraNode = $sel[1];
	setAttr ($cameraNode + ".scaleX") 1;
	setAttr ($cameraNode + ".scaleY") 1;
	setAttr ($cameraNode + ".scaleZ") 1;

	float $scaleX = `getAttr ($sel[1]+".scaleX")`;

	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;

	float $distance = `getAttr ($ddShape+".distance")`;
	float $correctedDistance = $distance / $scaleX;
	connectAttr -f ($bokehNode+".message") ($cShape[0]+".miLensShader");
	setAttr ($bokehNode+".plane") $correctedDistance;
}
bokeh();



#382

First of all if this question is in the wrong place I apologize in advance, I am new to posting on forums. :wavey:

What I want to do is export vertex weights from a skin mesh in a format I can import into an OpenGL application. (Ideally without a library such as the FBX library)

I have a skin mesh attached to a skeleton in Maya. I can load .obj files into my OpenGL application so the model itself is not a problem. What I want to have is the numerical values of the weights for each vertex in my Maya model, and the bone those weights correspond to. I have a skeleton in OpenGL and this skeleton is driven in real time by a user. What I am looking for is a script to export the weights in a format such as .txt format so I can attach a skin mesh to this OpenGL skeleton.

Does anyone know of a script that will do this? If not is it worth the time to teach myself MEL to script this exporter or should I learn Python? I have written a few simple MEL scripts but I am familiar with JAVA so perhaps Python is the way to go?


#383

Hi,

I’m building a UI for one of my characters Rigg.
It’s almost done and works nicely so far. But I’m not totally happy with the selection method.

I’m using buttons to select the controllers. Those buttons are launching a “select” command.
Sometimes it would be nice to add to the current selection (-tgl tag) and sometimes it would be better to reset the selection (-r tag).

Here is exacly what I would like to achieve :

  • When you simply click the button it launch a "select -r "command
  • When you hold shift key on the keyboard and click the button it launch a “select -tgl” command

Is there’s a simple way to do that?

Thank you.


#384

This has been discussed many, many times before Boris… just do a search here for getModifiers, or select shift button.

:nathaN


#385

Thanks Nathan.
That was what I was looking for. Perfect !


#386

there is any script for recover corrupt .ma file …when i m opening it it stops at 85 percentage


#387

This script makes a simple gui that converts frame numbers from one frame-rate to another. It’s useful for animating when your reference footage was shot with a frame-rate that’s different from Maya’s.

It’s my first script and I hope that you all find it useful.
Thanks.

/* -----------------------------------------------------------------
 *			Quick Key Converter	
 *
 *	-Written by: Jonathan Strong  12/2010
 *
 *	This script provides an easy to use frame number converter that converts 
 *	frame numbers that use one frame-rate to frame numbers using a different frame-rate (ex: 24 fps to 30 fps).
 *	
 *	When sourced, the script will bring up the UI used to convert frame numbers automatically.
 *	To bring up the UI on your own, call QuickKey in the MEL command line.
 *
 *  -----------------------------------------------------------------
 */
 
 
 //*****************************************************************
 //******************** private procedures *************************
 
 
 /*------------------------------------------------
 *
 *	makes the UI used to convert frame numbers
 *
 * ------------------------------------------------
 */
 proc makeWindow(){
 
 	//standard window handling
 	if(`window -exists JS_QKeyUI`)
 		deleteUI JS_QKeyUI;
 
 
 	window -title "Quick Key Converter" -width 200 -height 400 JS_QKeyUI;
 	columnLayout mainCol;	
 
 	//used to select Maya's frame-rate
 	radioButtonGrp -numberOfRadioButtons 3 -label "Maya Frame Rate" -vertical
 			-labelArray3 "24" "30" "Custom" -changeCommand QKey_enableCstm myaFPSgrp;
 	
 	//used to specify a custom frame-rate for Maya
 	text -label "Custom Maya Rate";
 	textField -enable false -text "disabled" cstMyaFPS;	
 
 	//used to select the reference footage's frame-rate
 	radioButtonGrp 	-numberOfRadioButtons 3 -label "Reference Frame Rate" -vertical
 			-labelArray3 "24" "30" "Custom" -changeCommand QKey_enableCstm refFPSgrp;
 
 	//used to specify a custom frame-rate for the reference footage
 	text -label "Custom Reference Rate";
 	textField -enable false -text "disabled" cstRefFPS;	
 
 
 	//used to set the stepsize of the conversion 
 	//(basically whether every frame, every other frame, every 3rd frame, etc. gets converted)
 	intSliderGrp -label "Frame Step" -field true -value 1 -min 1 -max 60 
 			 -changeCommand QKey_cnvrtFrames stepSlidr;
 
 	//displays the converted frame numbers
 	textScrollList frameList;
 
 
 	//textfields used to set the first frame of animation in Maya and
 	//the start and end frames of the reference footage 
 
 	text -label "Maya Start Frame";
 	textField -text "1" myaStart;
 
 	text -label "Reference Start Frame";
 	textField -text "1" refStart;
 	
 	text -label "Reference End Frame";
 	textField refEnd;
 
 
 	//button used to convert frame numbers
 	button -label "Convert keys" -c QKey_cnvrtFrames convrtBtn;
 
 	showWindow JS_QKeyUI;
 
 }
 
 /* -------------------------------------------
 *
 * gets the default frame-rate specified by the selection represented by $indx
 * returns -1 if a default frame-rate does not exist for the selection
 *
 * --------------------------------------------
 */
 proc float getDefaultVal(int $indx)
 {
 
 	if($indx == 1)
 	{	
 		return 24.0;
 	}	
 	
 	if($indx == 2)
 	{
 		return 30.0;
 	}
 
 	return -1;
 
 }
 
 /* -----------------------------------------------------------------------------------
 *
 *   returns a float representing a user specified frame-rate, if the frame-rate isn't valid, the procedure returns -1 
 *   
 *   ($txtFld is the textField whose text is the custom frame-rate)
 *
 * ------------------------------------------------------------------------------------
 */
 proc float setCstFPS(string $txtFld)
 {
 
 	//convert the textField's text to an integer
 	int $txtAsInt = (int)`textField -q -text $txtFld`;
 
 	//check to see if the integer is a valid frame-rate
 	if($txtAsInt > 0)
 	{
 		//if it is update the textField with the accepted frame-rate
 		textField -e -text ("" + $txtAsInt) $txtFld;
 		return $txtAsInt;
 	}
 	else{
 		textField -e -text "" $txtFld;
 		return -1;
 	}
 
 }
 
 /* --------------------------------------------
 *
 *  returns a float representing the frame-rate determined by the UI, returns -1 if the frame-rate is invalid
 *  
 *  ($radGrp is the radioButtonGroup used to choose default or custrom frame-rates)
 *  ($txtFld is the textField used to specify a custom frame-rate)
 *
 *  --------------------------------------------
 */
 proc float getFPS(string $radGrp, string $txtFld)
 {
 
 	//get the integer representing which radio button has been selected
 	int $sel = `radioButtonGrp -q -select $radGrp`;
 	
 
 	if($sel != 3){
 
 		//if the selection is a default value return the default value for that selection
 		return getDefaultVal($sel);
 		
 	}
 	else{	
 		//return the custom frame-rate specified by the user
 		return setCstFPS($txtFld);
 	}
 	
 }
 
 /* ------------------------------
 *
 *  checks the text of the textField specified by $txtFld and returns an int based on its text
 *
 *  ($default: the default value that should be used if no value is specified in $txtFld)
 *  ($err: the value that should be used if an invalid value is specified in $txtFld)
 *
 *  ------------------------------
 */
 proc int chkVal(string $txtFld, int $default, int $err){
 
 	int $val;
 
 	string $txt = `textField -q -text $txtFld`;
 	
 	//if no value is specified, set the value to its default -- otherwise set $val based on $txt
 	if($txt == ""){
 		$val = $default;
 		textField -e -text ("" + $default) $txtFld;
 	}
 	else
 		$val = (int)$txt;
 
 	//checks to see if $val is invalid, if it isn't set it to $err and update $txtField with the valid value
 	if($val <= 0){
 		$val = $err;
 		textField -e -text ("" + $err) $txtFld;
 	}
 	else
 		textField -e -text ("" + $val) $txtFld;
 
 	return $val;
 
 }
 
 /* ------------------------------------------------
 *
 * gets the values for the start and end frames of the conversion 
 * and updates the textFields used to specify these frames 
 *
 * returns an int[] of {$strtMaya, $strtRef, $endRef}
 *
 *--------------------------------------------------
 */
 proc int[] getFrameVals()
 {
 
 	//set variables for start/end frames based on the textFields used to specify them
 	int $strtMaya = chkVal("myaStart", 1, 0);
 	int $strtRef = chkVal("refStart", 1, 0);
 
 	//calculate the default value for the end of the reference footage (the default is one second past the beginning)
 	int $refFPS = (int)getFPS("refFPSgrp", "cstRefFPS");
 	int $endDefault = $strtRef + $refFPS;
 
 	//find the end of the reference footage
 	int $endRef = chkVal("refEnd", $endDefault, $endDefault);
 
 	int $frameVals[] = {$strtMaya, $strtRef, $endRef};
 	return $frameVals;
 }
 
 
 //*********************************************************
 //*************** global procedures ***********************
 
 /* -------------------------------------------------
 *
 *  procedure the user calls to make and show the UI
 *
 *  -------------------------------------------------
 */
 global proc QuickKey()
 {
 	//make and show the UI
 	makeWindow;
 }
 
 
 
 /* ------------------------------------------------------
 *
 *  turns the textFields that allow the user to specify custom frame-rates 
 *  on or off based on the user's selection in the myaFPSgrp & refFPSgrp radioButtonGrps
 *
 *  ------------------------------------------------------
 */
 global proc QKey_enableCstm(){
 	
 	int $selMya = `radioButtonGrp -q -select myaFPSgrp`;
 	int $selRef = `radioButtonGrp -q -select refFPSgrp`;
 
 	if($selMya != 3)
 		textField -e -enable false -text "disabled" cstMyaFPS;
 	else{
 		string $txt = `textField -q -text cstMyaFPS`;
 
 		if($txt == "disabled")
 			textField -e -enable true -text "" cstMyaFPS;
 	}	
 
 	if($selRef != 3)	
 		textField -e -enable false -text "disabled" cstRefFPS;
 	else{
 		string $txt = `textField -q -text cstRefFPS`;
 		
 		if($txt == "disabled")
 			textField -e -enable true -text "" cstRefFPS;
 	}
 		
 }
 
 
 /* -----------------------------------------------------------------------------------------
 *
 *  converts the frame numbers from one frame-rate to the other
 *
 * -----------------------------------------------------------------------------------------
 */
 global proc QKey_cnvrtFrames()
 {
 
 	//Maya's frame-rate and the frame-rate of the reference footage
 	float $myaFPS = getFPS("myaFPSgrp","cstMyaFPS");
 	float $refFPS = getFPS("refFPSgrp", "cstRefFPS");
 
 	if($myaFPS < 0)
 		error (" The value specified for Maya's frame-rate is not valid. ");
 	if($refFPS < 0)
 		error (" The value specified for the reference footage's frame-rate is not valid. ");
 
 
 	//get the values that determine the range of the conversion
 	int $validVals[] = getFrameVals();
 	int $strtMaya = $validVals[0];
 	int $strtRef = $validVals[1];
 	int $endRef  = $validVals[2];
 
 
 	//get the step size for the for loop from the stepSlidr
 	int $stepSize = `intSliderGrp -q -value stepSlidr`;
 
 	//find out the frame number in Maya that corresponds to the last frame of the reference footage
 	int $endMaya = (int)((($endRef - $strtRef)/ $refFPS) * $myaFPS);
 	$endMaya += $strtMaya;
 
 	//used to format the contents of frameList to make it more legible
 	int $cntr = 0;
 
 
 	//fill up the textScrollList frameList with the converted frames
 	textScrollList -e -removeAll frameList;
 	textScrollList -e -append "Maya Frame 	 Reference Frame" frameList;
 	textScrollList -e -append "______________________________" frameList;
 
 
 	for ( $x = $strtMaya; $x <= $endMaya; $x += $stepSize )
 	{
 		int $result = $x - $strtMaya;
 		$result = (int)(($result / $myaFPS) * $refFPS);
 		$result += $strtRef;		
 
 		textScrollList -e -append ( $x + "	" + $result) frameList;
 
 		if( ($cntr % 5) == 0 && $cntr > 0)
 			textScrollList -e -append "--------------------------" frameList;
 		
 		$cntr++;
 	}
 
 }
 
 //******************** end of procedures *******************************
 
 	//makes and shows the UI when the script is sourced through the script editor
 	makeWindow;

#388

Hey friends Let start Mel Script challenge on every month with different different topics.It will be fun,what you think huh??
Please Reply with your opinion.Thank you


#389

Sounds fun. :slight_smile:


#390

Nah, you’ll just win! :shrug:
But I do agree, it would be very beneficial to learn how others chose to construct the same script function. :buttrock:


#391

Hi guys, newish to MEL. I want to be able to select an object at the top of a given heirarchy and search through the children below it to locate a particular type of object within the heirarchy. I have tried the listNodes command and also the ls -type command but this just returns all of the types of object I am looking for in the whole scene. Is there anyway to specify to just look within a selected heirarchy?

I am sure this is quite simple, but as I am still learning I would probably go a long way round when there is a quicker, better alternative.

Thanks

EMJAY
proc d_oh()

{

string $remindMe = “DONT FORGET THE COLON”

}

//Result: you forgot the colon

coding humour…

FAIL

hahahahahhah. MEL is a fickle mistress, camelCase that code!:wip:


#392

Try looking at the pickwalk command.


#393

hey Malcom, you should probably have started a new thread for this… anyway, here’s one solution:

ls -sl -dag -l -type "pointLight";

the -sl flag is the most important in your case because it restricts the list to the selection, and the -dag flag tells it go list ALL the dag nodes underneath. The -l flag returns the long/full dag paths and the -type “pointLight” tells it to return only pointLights, obviously you would change this to your desired node type. You could even add a wildcard search term at the end to find pointlights with a specific name:

ls -sl -dag -l -type "pointLight" "*flicker*";
// will find any pointLight under the selected heirarchy that has "flicker" somewhere in its (shape) name

Check the docs for ls as it is a MOST powerful listing function that many people overlook, coding stupidly long or inefficient functions to get something a single ls would manage.

The pickWalk command is for changing selection, and I don’t think a very efficient way of working on items inside a script.
:nathaN


#394

Nice, I always forget how powerful the ls command is, even in other languages!


#395

Ah this one caught my eye, due to the fact that I’ve been trying to put together a mel mixer board for VRay lights in a scene similar to one I did for MR/Maya lights. Unfortunately VRay lights only get listed as transform nodes, and the only way I’ve found of listing them so far* is messing around in the defaultLightSet. Nothing to specifically denote them as VRay.

Wildcarding “VRay” doesn’t help if they’ve been renamed either :confused:

*with obviously limited Mel script knowledge.


#396

Hey Reeks, long time no see… Every geomeric/physical/moveable object in Maya consists of a parent transform and a shape node below, meshes, nurbs, lights, cameras, action-er-etc… I have no idea what vRay lights are but they must have a shape node below their transform that hold their visible locator and their light properties.

select one and then type: ls -sl -dag -st which should return something like:
// Result: vrayLight01 transform vrayLightShape01 vrLight
which shows the transform name, then it’s type, then it’s shape name and shape type.
:nathaN


#397

Oh always in the background, soaking up the knowledge. Actually, mel scripting for me is sporadic and usually due to situational needs.

And good, god you’re fast on the ball as ever !

Ohh dear… so simple!
// Result: VRayLightSphere1 transform VRayLightSphereShape1 VRayLightSphereShape //

Thank you NN! I can honestly say it’s your input (as well as JSChiek) that makes the learning of mel scripting enjoyable. One of these fine days I’ll take the Python Plunge, but still got a long way of learning the mel ropes to go first as you can tell ;p


#398

Hi guys, thanks for the replies.

What can I say, except D`oh.

Had managed to source a solution which is what you guys have suggested but I am very grateful that there are peeps like you guys ready to offer advice. I seem to overcomplicate things when writing MEL, often going the long way, but each day is a bit easier.

Will be posting the code for what I have been working on shortly.

Thanks


#399

Hello,

here is my first attempt towards MEL scripting

i have done a quick Blueprint Manager to ease in the task of setting up planes shaders etc for Vehicle / character Modelling.

i am still learning so there might be a few issues here and there but will solve those, once i get good idea and reference on MEL.


#400

Toggles double sided on selected objects. Handy to keep polys down.


  for ($node in $selection) 
  { 
  	 if ( getAttr ($node + ".doubleSided") == 1) 
  	 { 
  		  setAttr ($node + ".doubleSided") 0; 
  	 } 
  	 else 
  	 { 
  		  setAttr ($node + ".doubleSided") 1; 
  	 } 
  };
  

Also, I lost my binding for softSelection so had to write something for that:


 int $softVar = `softSelect -q -sse`;
 switch ($softVar)
 {
 case 1:
 softSelect -sse 0;
 break;
 
 case 0:
 softSelect -sse 1;
 break;
 }
 

And lastly, found a good script :Maya Mel script Better Combine
Keeps grouping, merges meshes together if verticies are close and centers pivot. What Maya’s combine should be.