MEL scripts


#21

ahh, got it - well, my manual doesn’t show me the current (live) values of the node’s attribute yet :slight_smile: - would be nice though if someone could make a link to the html documentation showing the documentation of the currently selected node and it’s active values


let me add - i’m using this one primarily for developing scripts - selecting nodes and looking up attributes in the attribute editor (opening the panes) can be tedious if i want to quickly verify conditions


#22

in the hypershade that is already there…
right click on the bottom of a node and the DG node help will pop up when you select the “help” line at the very bottom


#23

here are some really handy ones:

fromNativePath (windows to unix path string conversion)

toNativePath (windows to unix path string conversion)

filterExpand (expand selections like .cv[1:12][2:13] to single occurances)

encodeString (encode a string to escape characters like \ " )

baseName (get base name from a path string)
dirName (get the directory from a path string)

cmdFileOutput (writes output to a file)

flushUndo (clear the undo buffer: very handy in scripts that change a lot during execution to prevent overflow)

hope you found one, that you did not already know :slight_smile:

cheers

alexx


#24

öäähmm yes some :slight_smile:

mel is such a wonderfull thing in maya and it makes the real power. wrote a few nice scripts for good old stevie (you know who i mean :slight_smile: ) but i definitly need to spend more on this :slight_smile:


#25

so here’s one script i wrote the night long.

then i wanna weight a character and i use the paint weights tool it’s difficult to select a joint and rotate him a bit to get another position and look how the skin mooves. i have to leave the paint tool select the joint and rotate it. (i know that there is a way with attrCollection, but attrCollection you first have to set all up)

this script is very easy to handle. there are two ways. you can load in only selected joints or the whole hirarchie of the selected joint. after that you can see your joints in the top window. if you select one you will see all the bound (to this joint) geometry.

the sliders on bottom (X-Axis;Y-Axis;Z-Axis) you can handle the rotations. there are also input fields for the min, max and current. if an attribute is locked, the fields and slider will also be locked.

now you can select a geometry from the list and hit paint. you’ll be still able to rotate via the slider then the paint window is open.

i’m still not finished with commenting all out.

comments are very warm welcome :slight_smile:

svenip

–==edit==–

updated with a more commented file


#26

Don’t know if this allready exsist…
Just a little handy script if you are tired of deleting nodes from the Hypergraph.
Select a Node in the Channelbox, execute the script and the node is deleted:


string $Object[] = `ls -sl -tr -s`;
select -d $Object;
delete;
select $Object;


#27

your script is good svenip but you can simply animate the bone where you working on and when you want to check the result you use your time slider and you can keep paint the weight


#28

yeah i know HADES :slight_smile: it lacks a bit of usefullness because there are more ways (as i said via the attrCollection or your way) but it’s just a start, i wll add more functions i’m always searching for then i do skinning :slight_smile:


#29

cool svenip keep it up…as l said your script is good but my way of skinnig is with lattice and flexor l got better result in no time with soft skin this take more time to get the same result if you got a tipm for smooth skin or a good tutorail tell me l will try it …l m working in a 3d bisnees and l lways use this way…maybe if lget a better result in smooth that will be great…keep it up


#30

Here’s one of several name handling tools I’ve knocked out recently. Select any source object with left or right in its name and then a target object. The target will be renamed to that of the source with the opposite side.

For instance. If you select left_ulna and then select another joint and run the script the target joint will become right_ulna.

-----snip-----
proc int itemNthString (string $item, string $array[])
{
int $x;
int $theIndex = -1;

for ($x=0; $x<size($array); $x++)
{
	if ($array[$x] == $item)
	{
		$theIndex = $x;
		break;
	}
}

return ($theIndex);

}

proc int stringWordPosition (string $item, string $matchString, string $wordChar){
string $tokenList[];
int $position;

tokenize $item $wordChar $tokenList;
$position = (`itemNthString $matchString $tokenList` + 1);

return $position;

}

proc int stringContains (string $theString, string $item){
string $matchString = ($item + “+”);
int $returnInt = 0;

if (`match $matchString $theString` == $item){
	$returnInt = 1;
}

return $returnInt;

}

global proc string stringReplaceNthWord (string $item, string $replace, int $position, string $wordChar){
string $tokenList[];
string $returnString;
int $x, $y;

tokenize $item $wordChar $tokenList;
$y = size($tokenList);

for ($x=0; $x<$y; $x++){
	if ($x != ($position -1)){									//is this replace or copy?
		if ($x != ($y-1))										//is this the last word?
			{$returnString += ($tokenList[$x] + $wordChar);}	//if not, then it's x + a wordChar
		else
			{$returnString += $tokenList[$x];}					//else, it's just x
	}
	else{														//replace
		if ($x != ($y-1))
			{$returnString += ($replace + $wordChar);}
		else
			{$returnString += $replace;}
	}

}

return $returnString;

}

global proc liftNflopName (){
string $sel[] = ls-sl;
string $side;
string $flopName;

int		$position;

if (`stringContains $sel[0] "left"` == 1){
	$side = "left";
	$position = `stringWordPosition $sel[0] $side "_"`;
	$flopName = `stringReplaceNthWord $sel[0] "right" $position "_"`;
}

if (`stringContains $sel[0] "right"` == 1){
	$side = "right";
	$position = `stringWordPosition $sel[0] $side "_"`;
	$flopName = `stringReplaceNthWord $sel[0] "left" $position "_"`;
}

rename $sel[1] $flopName;

}

-jl


#31

didn’t test it yet, but that sounds great bigfatMELon :thumbsup:


#32

Originally posted by alexx

filterExpand (expand selections like .cv[1:12][2:13] to single occurances)

You mean… with filterExpand, I can convert the line .cv[1:12] to .cv[1,2,3,4,5,6,7,8,9,10,11,12]? (Ok can’t remember how it was in MEL exactly, but you get the point)

:eek:
Holy beep alexx! You’re my hero now! :beer:


#33

Since this is the mel thread, here’s a little window I map to a hotkey that will bring up a text field to let you search for mel commands. I get tired of slumming through the online reference. Works on w2k, havn’t tested it on other platforms… could get hairy the way it sources the paths…

/////////////////////////
//
// UI_melCmdFinder.mel
// Author: Warpcat
// Description
// A little window that opens the help documentation.
//
///////////////////////////

global proc UI_melCmdFinder()
{
if ( window -exists UI_melCmdFinder )
deleteUI UI_melCmdFinder;

window -t "MEL Command Finder Window" -rtf 1 UI_melCmdFinder;		
	columnLayout -adj 1;
		textFieldGrp -l "Mel Command Search:" -cc EP_showMelHelp helpField;
		button -l "Mel Command Reference Library" -c EP_showMelLibrary;
		button -l "Node and Attribute Refernce Library" -c EP_showNodeLibrary;
showWindow;
}

global proc EP_showMelHelp()
{
string $helpCommand = textFieldGrp -q -tx helpField;
help -doc $helpCommand;
}

global proc EP_showMelLibrary()
{
showHelp -docs “Commands\Index\index.html”;
}

global proc EP_showNodeLibrary()
{
showHelp -docs “Nodes\Index\indexAlpha.html”;
}

///////////////////////////


#34

that’s a really helpfull script warpcat. thank you, it speeds up the process :thumbsup:

:wavey:


#35

Hey folks,
Here’s a script I wrote yesterday before work. It’s based on a lighting TD tool they used to use (may still) at ILM called “solo render”. This is for those scenes where you have a ton of lights but just want to see the effect of one or two of them on the scene without having to hide lights or create a bunch of weird layers.
With this, you just click any lights you want to use in the render (though the outliner, viewport, or whatever way you want) and then run soloRender. I have it bound to ALT-r so it’s super fast.

I have a few things I’d like to add to it, but here it is. It seems to work well:


// soloRender()
// by Alec Fredericks

global proc soloRender()
	{
	string $arrayLights[];
	string $itemLight;

	int $arrayStart = 0;

	string $arrayLightVis[];
	string $arrayLightVisVal[];
	int $visState;

	string $pickedLights[] = `ls -sl`;
	$arrayLights = `ls -lights`;
	for ($itemLight in $arrayLights)
	{
		$visState = eval("getAttr " + $itemLight + ".visibility");
		$arrayLightVis[$arrayStart] = $itemLight;
		$arrayLightVisVal[$arrayStart] = $visState;
		if (stringArrayCount($itemLight,`listRelatives -s $pickedLights`) > 0)
			eval("setAttr " + $itemLight + ".visibility 1");
			else
				eval("setAttr " + $itemLight + ".visibility 0");
		$arrayStart = $arrayStart + 1;
	}

	renderIntoNewWindow render;

	int $sizeArray = size($arrayLightVis);
	int $x;
	for ($x=0;$x<$sizeArray;$x++)
		{
		if ($arrayLightVisVal[$x] == 1)
			eval("setAttr " + $arrayLightVis[$x] + ".visibility " + $arrayLightVisVal[$x]);
		}


	clear($arrayLightVis);
	clear($arrayLightVisVal);
	clear($arrayLights);

	} // end proc

Let me know if any of you use this and have problems with it.
I’ll probably rewrite this using a matrix instead of two arrays and the coding is a bit sloppy, but…oh, well.
Alec


#36

Originally posted by -wT-
[B]

You mean… with filterExpand, I can convert the line .cv[1:12] to .cv[1,2,3,4,5,6,7,8,9,10,11,12]? (Ok can’t remember how it was in MEL exactly, but you get the point)

:eek:
Holy beep alexx! You’re my hero now! :beer: [/B]

yep

a selection like: .cv[1:3]
gets converted and returned to:
.cv[1] .cv[2] .cv[3]

as i said… i wrote my own script to do that for all occasions before i found the mel command myself…
bit myself in the beep :wink:

btw… if there is any need for it i can post a newer version of my “fakeDepth” script that includes particles now as well (since 4.0 does not render particles with z-channel in sw render anymore… hell knows why)

cheers

alexx


#37

Originally posted by alexx
[B]

yep

a selection like: .cv[1:3]
gets converted and returned to:
.cv[1] .cv[2] .cv[3]

as i said… i wrote my own script to do that for all occasions before i found the mel command myself…
bit myself in the beep :wink:

btw… if there is any need for it i can post a newer version of my “fakeDepth” script that includes particles now as well (since 4.0 does not render particles with z-channel in sw render anymore… hell knows why)

cheers

alexx [/B]

Yeah, tried it as soon as you posted that, and it worked :slight_smile:
And yes, I was doing just the same thing, converting them myself with two to three lines of extra code everytime, I think the speed of the script increased around 300% :smiley:
Thanks again :wink:


#38

Hey, -wT- and alexx, don’t forget the ‘flatten’ (or -fl) flag, it works like filterExpand but can be used as part of the list command, so the line:

string $templist[] = ls -fl -sl;

will put each selected item into its own array entry. Just like filterExpand but even less typing :slight_smile:

This is a little script I wrote for working with blendshapes, it will transfer the current component selection from one target to another (as long as the topology is the same). It’s just two or three loops and a bit of string manipulation, but it’s been incredibly useful for the way I work.

(BTW rename to transferSelection.mel to use it).

Wabo.


#39

Originally posted by Waboflex
[B]Hey, -wT- and alexx, don’t forget the ‘flatten’ (or -fl) flag, it works like filterExpand but can be used as part of the list command, so the line:

string $templist[] = ls -fl -sl;

will put each selected item into its own array entry. Just like filterExpand but even less typing :slight_smile:

This is a little script I wrote for working with blendshapes, it will transfer the current component selection from one target to another (as long as the topology is the same). It’s just two or three loops and a bit of string manipulation, but it’s been incredibly useful for the way I work.

(BTW rename to transferSelection.mel to use it).

Wabo. [/B]

Yup, that works, and I use the -fl flag all the time, but it’s not available when converting from selection to another (Which is crucial in my script), and then you have two choices, either convert the selection from i.e. face to verticles, select all the verts and use the “ls -sl -fl” (Like I did, but is horribly slow), or the much faster way, convert the selection from i.e. face to verticles and the filterExpand the list.
Clever :slight_smile:


#40

I dunno if this one has been posted yet but i use it all the time with paint effects.

This darkens the stroke you have selected, hit it a couple times and if its still not dark enough hit it again. :slight_smile:

scaleBrushBrightness 0.95 0 ;

turns the brightness down 5 percent everytime, but you can go ahead and change the number to whatever you like. Did i need to tell you pro’s that, lol probaly not.

yup this one is alot simpler than everyone elses i read up here. But hey its the only one i know right now.
later guys
Rudity