MEL scripts


#141

no way…thanks equinox


#142

My friend Doogie on here,he made this script for me and my friend. it does like wings 3d flatten. if you want all your verts at the X axis it will do that, it also does z y, but he added a value to this tool which is great. enjoy, its a awesome script. thanks DOOGIE! i also asked if he could make it so if you have edges, it would flatten the edges. it does now, but yuo get weird results. if he does ill update.

// Author: Paul Franz (paul@paulfranz.com)
// Date: 12-22-2003
// Description: Snaps selected verts to defined axis
//
// If ya wanna use or modify it (in other
// scripts), i dont really care. Just let me know.

global proc pfSetVal ()
{
$win = “pfSetValWin”;
if (window -exists $win)
deleteUI $win;

pfSetValWin $win;

showWindow $win;

}

proc pfSetValWin (string $win)
{

// create the window
window -t "pf Set Value" $win;

columnLayout -cat both 5 -adj true -rowSpacing 1;

radioButtonGrp
	-numberOfRadioButtons 3
	-label "Axis:"
	-labelArray3 "X" "Y" "Z"
	-on1 ""
	-on2 ""
	-on3 ""
	-sl 1
	axisRadButGrp;

floatSliderGrp -minValue -50.0 -maxValue 50.0 -label "Value:" -field true pfSetValOffset;

button -l "Ok" -c "pfSetTheVal()";

}

proc pfSetTheVal()
{
string $sel[] = ls -sl -fl;
string $vert;
string $axis;
float $transVal[];
int $tmpINT = radioButtonGrp -q -sl axisRadButGrp;
float $offset = floatSliderGrp -q -value pfSetValOffset;

switch ($tmpINT){
		case 1:
			$axis = "x";
			break;
		case 2:
			$axis = "y";
			break;
		case 3:
			$axis = "z";
			break;
		default:
			error "No axis selected. Pick a radio box";
			break;
}

if (size($sel) == 0)
{
	error "select something";
}


for ($vert in $sel)
{
	$transVal = `xform -q -ws -t $vert`;
	
	switch ($axis){
		case "x":
			xform -ws -t $offset $transVal[1] $transVal[2] $vert;
			break;
		case "y":
			xform -ws -t $transVal[0] $offset $transVal[2] $vert;
			break;
		case "z":
			xform -ws -t $transVal[0] $transVal[1] $offset $vert;
			break;
		default:
			error "No axis selected";
			break;
	}
}

}

pfSetVal();
// eof


#143

I don’t know if ths is the right thread to post this in, but I’m making a skin weights transfer script that’s got a few useful features, aeSkinWeightsTransfer. It’s not UV- or topology dependant, but instead depends on the world space positions of the weighted control points, kind of like Michael Comet’s saveWeights.mel, but it can average weights between several exported points in the vicinity of the import point if none is found at the same location.

So far, I’ve gotten it to work with the features I want, but I haven’t written a proper manual yet.

Get it here.


#144

http://www.cgtalk.com/showthread.php?s=&threadid=124771

just check out the thread and give C&C please :wink:

cheers

psycho


#145

a script that create a motion field for the fluids.

its altmost the same that the maya fluids but this calculate the force from the world position and not from the previous key.

you only have to select the geometry first and then the fluid and type fvMotionField

global proc fvMotionField()
{
string $lista[];
$lista= `ls -sl `;	
string $padre, $fluido;
$padre=$lista[0];
$fluido=$lista[1];
select -cl;
string $nombre[]= `uniform`;
string 	$elemento;
$elemento=$nombre[0];
connectDynamic -f $elemento $fluido ;
print ($elemento+" "+$padre+"
");
parent $elemento $padre;
setAttr ($elemento+".translateX") 0;
setAttr ($elemento+".translateY") 0;
setAttr ($elemento+".translateZ") 0;
setAttr ($elemento+".rotateX") 0;
setAttr ($elemento+".rotateY") 0;
setAttr ($elemento+".rotateZ") 0;
setAttr ($elemento+".volumeShape") 2;
if (!`attributeExists "pushIntensity" $elemento`)
	{
	addAttr -ln pushIntensity -dv 2 -at double  $elemento;
	setAttr -e -keyable true ($elemento+".pushIntensity");
	}
if (!`attributeExists "antX" $elemento`)
	addAttr -ln antX -at double  $elemento;
if (!`attributeExists "antY" $elemento`)
	addAttr -ln antY -at double  $elemento;
if (!`attributeExists "antZ" $elemento`)
	addAttr -ln antZ -at double  $elemento;
string $expresion="float $newX,$newY,$newZ;
";
		$expresion+="float $aX,$aY,$aZ;
";
		$expresion+="float $distX,$distY,$distZ;
";
		$expresion+="float $longitud;
";
		$expresion+="float $posicion[]=`xform -q -ws -t "+$elemento+"`;
";
		$expresion+="$newX=$posicion[0];
";
		$expresion+="$newY=$posicion[1];
";
		$expresion+="$newZ=$posicion[2];
";
		$expresion+="if (frame>0)
";
		$expresion+="	{
";
		$expresion+="	$aX=`getAttr "+$elemento+".antX`;
";
		$expresion+="	$aY=`getAttr "+$elemento+".antY`;
";
		$expresion+="	$aZ=`getAttr "+$elemento+".antZ`;
";
		$expresion+="	}
";
		$expresion+="else
";
		$expresion+="	{
";
		$expresion+="	$aX=$newX;
";
		$expresion+="	$aY=$newY;
";
		$expresion+="	$aZ=$newZ;
";
		$expresion+="	}
";
		$expresion+="$distX=$aX-$newX;
";
		$expresion+="$distY=$aY-$newY;
";
		$expresion+="$distZ=$aZ-$newZ;
";
		$expresion+="$longitud=`sqrt($distX*$distX+$distY*$distY+$distZ*$distZ)`;
";
		$expresion+="if ($longitud>0.0001)
";
		$expresion+="{
";
		$expresion+="	$distX/=$longitud;
";
		$expresion+="	$distY/=$longitud;
";
		$expresion+="	$distZ/=$longitud;
";
		$expresion+="}
";
		$expresion+=$elemento+".directionX=$distX;
";
		$expresion+=$elemento+".directionY=$distY;
";
		$expresion+=$elemento+".directionZ=$distZ;
";
		$expresion+="setAttr "+$elemento+".antX $newX;
";
		$expresion+="setAttr "+$elemento+".antY $newY;
";
		$expresion+="setAttr "+$elemento+".antZ $newZ;
";
		$expresion+=$elemento+".magnitude="+$elemento+".pushIntensity*$longitud*20;
";
expression  -s $expresion;
	
}


#146

Levitateme:
that “vertex flatten script”… emm… that can be done with a snapping in maya…
why the script?

cheers

alexx


#147

I need to export the component spreadsheet of my skin weights. I don’t want to use the weight map import/export because of the inconsistency of the imported maps. If anyone could help me out with a script thats already written or send me down the right path I would greatly appreciate it. Something that could paste in to Excel would be nice…


#148

this is a basic script to read the weight of the vertex in a smooth bind, i hope can help you to write a better script


global proc fvPesos()

{
string $objeto[];
string $geometria;
$objeto= `ls -sl`;
$geometria=$objeto[0];
$poligono=`pickWalk -d down `;
print ($poligono[0]+"
");
string $deformador[]=`listConnections ($poligono[0]+".inMesh")`;
print ($deformador[0]+"
");
print ($geometria+"
");
select -r $geometria;
PolySelectConvert 3;
string $vertices[]=`ls -fl -sl`;
string $vertice;
int $contador;
string $joint[] =`listConnections ($deformador[0]+".matrix")`;
int $valor;
for ($vertice in $vertices)
        {
         print ($vertice+"
");
         float $valores[]=`skinPercent -q -v  $deformador[0]        $vertice`;
         for ($valor=0;$valor<size($valores);$valor++)
               {
                print ("joint-"+$joint[$valor]+" "+$valores[$valor]+" ");
                }
          print "
";

          }
}

i think that can be easy write the data to a file.


#149

I don’t know if this is the right place to ask this but…I want to write a script that toggles -wos of the selected geometery only. However, the only command that toggles wireFrameOnShaded is the modelEditor command (as u all probably already know) and it does it to all the geometry in the scene. Hence, my dilema; it’s not at all like using the -xRay flag with the displaySurface command that all you have to do is say…displaySurface -xRay 1 or 0 ball for example. If I try to do it like that with the modelEditor command, modelEditor -e -wos 1 ball, I get an error in the ScriptEditor: Object not found: |ball. The default script that Maya runs for this is…modelEditor -e -wos 1 or 0 modelPanel4; Someone suggested that I use the filterExpand command but even then I still have the same problem. Maya can’t find the selected geometry. Is there a way to cycle through the current modelPanel and toggle the -wos of the specified geo? Is this even possible? I’m not looking 4 an easy answer, and if someone out there has already written a script that does, this don’t post the final script, I just need some guidance. I’m looking forward to hear from some of your suggestions. Thanx.


#150

Here’s one I just finished up. Can’t say it’s going to be anything ground breaking, but I think it might speed up workflow a bit. It provides you with a single window to lock out and hide attributes on your character controls.


//////////////////////////////////////////////////////////////////
// 								//
//	jhCleanControls.mel					//
//								//
//	Author: Jared Hromika - [email]jhromika@hromikarenders.com[/email]	//
//	Date: 3-23-04						//
//								//
//	Purpose: To expedite the process of locking and hiding	//
//		 various attributes on controllers.		//
//								//
//////////////////////////////////////////////////////////////////


global proc jhCleanControls ()
{
	$win = "jhCleanControlsWIN";

	if (`window -exists $win`)
		deleteUI $win;

	jhCleanControlsWin $win;

	showWindow $win;
}

global proc jhCleanControlsWin (string $win)
{
	window -t "jhCleanControls" -w 600 $win;
	
	columnLayout -cat both 5 -adj true;
	
	separator -height 10 -style "none";
	
	rowLayout -numberOfColumns 2
		-columnWidth2 200 350
		-columnAttach 1 "both" 	5
    		-columnAttach 2 "both"  5;

	columnLayout -cat both 5 -adj true;
	
	textScrollList -ams true -nr 5 -w 150 jhCleanControlsTSL;
	
	button -l "Add Objects" -c jhAddObjects;
	button -l "Remove Objects" -c jhRemoveObjects;
	
	setParent..;

	columnLayout;

	radioButtonGrp
		-numberOfRadioButtons 2
		-labelArray2 "Unlock" "Lock"
		-select 2		
		jhRadioGrpLock;

	radioButtonGrp
		-numberOfRadioButtons 2
		-labelArray2 "Unkeyable" "Keyable"
		-select 1
		jhRadioGrpKey;

	separator -height 10 -style "none";	

	string $label[] = {"Rotate", "Translate", "Scale"};
	string $checkName[] = {"jhCheckGrpRotate", "jhCheckGrpTranslate", "jhCheckGrpScale"};

	for ($i = 0; $i <= 2; $i++)
	{
		checkBoxGrp
    			-numberOfCheckBoxes 3
	    		-label $label[$i]
    			-labelArray3 "X" "Y" "Z"
			-columnWidth4 60 40 40 40
			$checkName[$i];
	}

	checkBoxGrp
    		-numberOfCheckBoxes 1
	    	-label "Visibility"
		-columnWidth2 60 40
		jhCheckGrpVisibility;

	setParent..;
	setParent..;

	separator -height 10 -style "out";
	
	button -l "Clean Controls" -c jhCleanControlsRun;	
}

global proc jhCleanControlsRun ()
{
	string $controls[0];
	string $axis[] = {"", "X", "Y", "Z"};
	string $transform[] = {"", "rotate", "translate", "scale"};
	string $jhTransform[] = {"", "jhCheckGrpRotate", "jhCheckGrpTranslate", "jhCheckGrpScale"};

	int $checkVal;

	$controls = `textScrollList -q -ai jhCleanControlsTSL`;
	$lockSel = `radioButtonGrp -q -sl jhRadioGrpLock` - 1;
	$keySel = `radioButtonGrp -q -sl jhRadioGrpKey` - 1;

	// For each control in the text scroll list it retrieves the value of the checkbox for each of the three
	// 	transforms and their axis.  If the box is checked, the attribute is locked / unlocked and
	//	made keyable or unkeyable based on the radio button selections.
	
	// The visibility check is outside of the nested loops because it doesn't have 3 axis like the others.
	
	for ($currentControl in $controls)
	{
		for ($i = 1; $i <= 3; $i++)
		{
			for ($j = 1; $j <= 3; $j++)
			{
				$checkVal = `checkBoxGrp -q ("-v" + $j) $jhTransform[$i]`;
			
				if ($checkVal == 1)
					setAttr -lock $lockSel -keyable $keySel ($currentControl + "." + $transform[$i] + $axis[$j]);
			}			
		}

		$checkVal = `checkBoxGrp -q -v1 jhCheckGrpVisibility`;

		if ($checkVal == 1)
			setAttr -lock $lockSel -keyable $keySel ($currentControl + ".visibility");
	}
}

global proc jhAddObjects ()
{
	string $objects[0];
	string $current[0];
	string $new[0];

	// Check the current selection, as well as the current values in the text scroll list.

	$objects = `ls -sl`;
	$current = `textScrollList -q -ai jhCleanControlsTSL`;
	
	// Clear the text scroll list.

	textScrollList -e -ra jhCleanControlsTSL;

	// Refill the list with the previous list as well as the current selection.  First the strings 
	//	are combined and then checked for duplicate entries.  These duplicate entries are then 
	//	removed and the list is repopulated.

	$new = `stringArrayCatenate $objects $current`;
	$new = `stringArrayRemoveDuplicates $new`;

	for ($item in $new)	
		textScrollList -e -a $item jhCleanControlsTSL;
}

global proc jhRemoveObjects ()
{
	string $currentSel[0];
	
	// Determine which objects are selected within the text scroll list.  These items are then removed.

	$currentSel = `textScrollList -q -si jhCleanControlsTSL`;

	for ($item in $currentSel)	
		textScrollList -e -ri $item jhCleanControlsTSL;	
}


#151

… a script that toggles -wos of the selected geometery only

-wos is a property of modelEditor so im pretty sure you cant write that script of your

However, the only command that toggles wireFrameOnShaded is the modelEditor command (as u all probably already know) and it does it to all the geometry in the scene.

wrong … because the -wos flag is specifically to modelEditor and it can be applied only to the modelEditor itself not to the geometry

If I try to do it like that with the modelEditor command, modelEditor -e -wos 1 ball, I get an error in the ScriptEditor: Object not found: |ball. Maya can’t find the selected geometry.

as expected because the ball is not a modelEditor. and Maya is looking for a modelEditor named ball

Is there a way to cycle through the current modelPanel and toggle the -wos of the specified geo? Is this even possible?

maybe in Maya 6 :bounce:


#152

Thanx. u’ve helped a lot. I guess I’ve actually found something that maya can’t do. Again thanx.


#153

Originally posted by abie1
Thanx. u’ve helped a lot. I guess I’ve actually found something that maya can’t do. Again thanx.

maya cant do because it wasnt suppose to do :smiley:


#154

what about the other wireframe on shaded? the one in the preferences under display… it isn’t -wos but -wsa

how do you toggle that?


#155

Originally posted by stallion151
[B]what about the other wireframe on shaded? the one in the preferences under display… it isn’t -wos but -wsa

how do you toggle that? [/B]

that wirefame on shaded is for selected objects in the scene, so if you want to select an object and don`t see his wireframe topology choose None there.

hope this helps


#156

yeh i have shelf buttons for that, but i find the shelf takes too much room and i am more of a hotkey kinda guy.

how do you write something like that? i know i should learn to write my own, but i keep making excuses… :rolleyes: so if you could help here it would be great.


#157

dunno if this will be any help to anyone?
i wrote this today, im learning mel so did this for practice. its a really stupid thing to do, but again its only for practice.
heres the script:

window -t “MELPracWindow” -wh 436 460;
columnLayout;
button -l “CreateSphere” -command “sphere”;
attrFieldSliderGrp -l “TranslateX”
-minValue -10 -maxValue 10 -cal 1 left
-adjustableColumn true -attribute nurbsSphere1.tx;
attrFieldSliderGrp -l “TranslateY”
-minValue -10 -maxValue 10 -cal 1 left
-adjustableColumn true -attribute nurbsSphere1.ty;
attrFieldSliderGrp -l “TranslateZ”
-minValue -10 -maxValue 10 -cal 1 left
-adjustableColumn true -attribute nurbsSphere1.tz;
attrFieldSliderGrp -l “ScaleX”
-minValue -10 -maxValue 10 -cal 1 left
-adjustableColumn true -attribute nurbsSphere1.sy;
attrFieldSliderGrp -l “ScaleY”
-minValue -10 -maxValue 10 -cal 1 left
-adjustableColumn true -attribute nurbsSphere1.sx;
attrFieldSliderGrp -l “ScaleZ”
-minValue -10 -maxValue 10 -cal 1 left
-adjustableColumn true -attribute nurbsSphere1.sz;
attrFieldSliderGrp -l “RotateX”
-minValue -360 -maxValue 360 -cal 1 left
-adjustableColumn true -attribute nurbsSphere1.rx;
attrFieldSliderGrp -l “RotateY”
-minValue -360 -maxValue 360 -cal 1 left
-adjustableColumn true -attribute nurbsSphere1.ry;
attrFieldSliderGrp -l “RotateZ”
-minValue -360 -maxValue 360 -cal 1 left
-adjustableColumn true -attribute nurbsSphere1.rz;
rowColumnLayout -numberOfRows 8 -rowHeight 1 25 -rowHeight 2 25 -rowHeight 3 25 -rowHeight 4 25 -rowHeight 5 25 -rowHeight 6 25 -rowHeight 7 25 -rowHeight 8 25
-rowAttach 1 “top” 10 -rowAttach 2 “top” 10 -rowAttach 3 “top” 10 -rowAttach 4 “top” 10 -rowAttach 5 “top” 10 -rowAttach 6 “top” 10 -rowAttach 7 “top” 10 -rowAttach 8 “top” 10;
button -l “CreateLambertNode” -command “shadingNode -asShader lambert;”;
button -l “CreateBlinnNode” -command “shadingNode -asShader blinn;”;
button -l “CreatePhongNode” -command “shadingNode -asShader phong;”;
button -l “Create PhongENode” -command “shadingNode -asShader phongE;”;
button -l “Create AnisotropicNode” -command “shadingNode -asShader anisotropic;”;
button -l “Create RampShaderNode” -command “shadingNode -asShader rampShader;”;
button -l “Create ShadingMapNode” -command “shadingNode -asShader shadingMap;”;
button -l “Create SurfaceShaderNode” -command “shadingNode -asShader surfaceShader;”;
button -l “AssignLambertToSphere” -command “defaultNavigation -source lambert2 -destination |nurbsSphere1|nurbsSphereShape1.instObjGroups[0] -connectToExisting;”;
button -l “AssignBlinnToSphere” -command “defaultNavigation -source blinn1 -destination |nurbsSphere1|nurbsSphereShape1.instObjGroups[0] -connectToExisting;”;
button -l “AssignPhongToSphere” -command “defaultNavigation -source phong1 -destination |nurbsSphere1|nurbsSphereShape1.instObjGroups[0] -connectToExisting;”;
button -l “AssignPhongEToSphere” -command “defaultNavigation -source phongE1 -destination |nurbsSphere1|nurbsSphereShape1.instObjGroups[0] -connectToExisting;”;
button -l “AssignAnisotropicToSphere” -command “defaultNavigation -source anisotropic1 -destination |nurbsSphere1|nurbsSphereShape1.instObjGroups[0] -connectToExisting;”;
button -l “AssignRampShaderToSphere” -command “defaultNavigation -source rampShader1 -destination |nurbsSphere1|nurbsSphereShape1.instObjGroups[0] -connectToExisting;”;
button -l “AssignShadingMapToSphere” -command “defaultNavigation -source shadingMap1 -destination |nurbsSphere1|nurbsSphereShape1.instObjGroups[0] -connectToExisting;”;
button -l “AssignSurfaceShaderToSphere” -command “defaultNavigation -source surfaceShader1 -destination |nurbsSphere1|nurbsSphereShape1.instObjGroups[0] -connectToExisting;”;
button -l “LambertAttributes” -command “showEditor lambert2;”;
button -l “BlinnAttributes” -command “showEditor blinn1;”;
button -l “PhongAttributes” -command “showEditor phong1;”;
button -l “PhongEAttributes” -command “showEditor phongE1;”;
button -l “AnisotropicAttributes” -command “showEditor anisotropic1;”;
button -l “RampShaderAttributes” -command “showEditor rampShader1;”;
button -l “ShadingMapAttributes” -command “showEditor shadingMap1;”;
button -l “SurfaceShaderAttributes” -command “showEditor surfaceShader1;”;
showWindow;

oh, and if you do run the script, you must first create a nurbs sphere. it should be called nurbsSphere1. the default. i havent figured out how to run the script without creating the sphere.


#158

Hey…

I was wondering how to query the number of vertices on a selected curve. MisterDi gave me a tip that this value equals degree + spans. So here’s the script, that adds vtxNum(number of vertices) attribute to the curve transform. You just select the curve and run the script. Now you can query this attribute for whatever operations you need to make on a per vertex basis.


string $sel[] = ls -dag -ap -sl;
int $degree = getAttr ($sel[1] + ".degree");
int $spans = getAttr ($sel[1] + ".spans");
int $vtxNum;

int $vtxNum = $degree + $spans;
addAttr -ln vtxNum -at long ("|" + $sel[0]);
setAttr -e -keyable true ("|" + $sel[0] + “.vtxNum”);
setAttr ($sel[0] + “.vtxNum”) $vtxNum;


ALES


#159

Hi there Mel scripters. How can I get my “spans UV” on Nurbs objects displayed as a HUD on my in my Maya window like my poly count is?

Can anyone help me with this. It’s really setting me back.


#160

You need 2 procs: 1 proc should return the .spansUV attr on the currently shape node; the second proc should create the HUD (and call the 1st proc). Like this:

global proc int[] dwGetSpansUV()
{
//Get selected obj.
string $sel[] = ls -sl -o;
//Return empty array if nothing is selected.
if (! size $sel)
return {};

//Get shapes (where .spansUV resides)
string $shape[] = listRelatives -s $sel[0];

//Return empty array if no shapes exist.
if (! size $shape)
return {};
//Return empty array if no spansUV attr exists.
if (! attributeExists "spansUV" $shape[0])
return {};

int $spansUV[] = getAttr ($sel[0] + ".spansUV");
return $spansUV;
}

{
if (!headsUpDisplay -exists dwHUDSpansUVDisplay)
{
headsUpDisplay
-section 4 -block 7 -blockSize “medium”
-label “spansUV:”
-labelFontSize “small”
-command “dwGetSpansUV”
-event “SelectionChanged”
dwHUDSpansUVDisplay;
}
else
headsUpDisplay -rem dwHUDSpansUVDisplay;
}

Here I didn´t make the 2nd a proc really; you can put that on a shelf as-is. The 1st proc must be global however, and you can save that to an extra .mel file if you want (dwGetSpansUV.mel). Note that the 1st proc returns an empty array if non of the necessary criteria are met. Also, note that if you have multiple objs selected, it will display the spans only for the first obj in the selection list.

:beer:
David