MEL scripts


#281

This is great…

Here is a simple yet useful MEL that I made…

ControlColor for overriding controller’s Color

// Use this tool to help Change the color of the controllers-----------------

 //User Interface--------------------- 
if (`window -exists WCO`) deleteUI WCO;
window 
	-wh 300 50
	-title "Control Colour Overide "
	-maximizeButton 0
	-rtf true
 
	 WCO;
columnLayout -adjustableColumn true ;
 
global string $color;
	$color = `colorIndexSliderGrp -label "Select Color" -min 2 -max 20 -value 10`;
 
button -label "Change Color" -c "colorMap";
 
showWindow WCO;
 
//Procedure for overriding color-------------------
proc colorMap () {
 
global string $color; 
 
int $colorQuery; 
 
$colorQuery = `colorIndexSliderGrp -q -v $color`;
 
string $Control[] = `ls -sl`;
 
string $sel; 
 
for ($sel in $Control){
 
	 setAttr ($sel+".overrideEnabled") 1;
 
setAttr ($sel+".overrideColor") ($colorQuery-1) ;
		}}
 
 
//The End-----------------------


#282

Hello, I created those two scripts. First one is a simpler version of the center pivot to vertex from, I think, previous page and second is also simpler version of swapnil3d’s copy shader script.

They’re working really nice but as a newbie to maya scripting (and newbie to programming in anything other than 8bit atari basic :wink: I have one question about ‘ls’ command. I’m using it for my second script to get the list of the currently selected objects and at the same time to get the list of shaders on that objects.

When I select ‘objects’ this command gives me list in slection order - selected first is first on that list, second - second etc. But when I’m selecting faces ‘ls’ command is sorting my selection list and when I was expected to get something like this:

“pPlane1.f[14] pPlane1.f[0] pPlane1.f[4]”

I get the “pPlane1.f[0] pPlane1.f[4] pPlane1.f[14]”. Is there any ‘not included’ in maya commands help switch to turn off the sorting by name? It’s a little weird that this isn’t sorting the objects by name but leave them in that order in wich you selected them.

Anyway my scripts:

pivot2vertex: choose vertex, execute the script


float $pos[] = `pointPosition`;

if( (`selectPref -q -aa`) == false )
	{
	selectPref -aa true;
	selectMode -o;
	xform -ws -piv $pos[0] $pos[1] $pos[2];
	selectPref -aa false;
	}
else
	{
	selectMode -o;
	xform -ws -piv $pos[0] $pos[1] $pos[2];
	}

copyshader: select several objects, execute the script to copy first object shader to other selected objects


string $objname[] = `ls -sl -fl`;

hyperShade -smn "";

string $shdname[] = `ls -sl -fl`;

select $objname;
hyperShade -assign $shdname[0];

EDIT: I just added more functionality to pivot script. Now you can also select whole object, one of its faces or edges. Script will put pivot in centre of selection for example in centre of face, edge or object. Selecting more than 1 faces/edges is also working…

mega.pivot.tool


if( (`selectMode -q -co`) == true )
	{
	if( (`selectType -q -v`) == true )
		{
		float $pos[] = `pointPosition`;

		if( (`selectPref -q -aa`) == false )
			{
			selectPref -aa true;
			selectMode -o;
			xform -ws -piv $pos[0] $pos[1] $pos[2];
			selectPref -aa false;
			}
		else
			{
			selectMode -o;
			xform -ws -piv $pos[0] $pos[1] $pos[2];
			}	
		}

	else
		{
		float $old[3] = `xform -q -ws -piv`;
		float $new[6] = `xform -q -ws -bb`;
		selectMode -o;
		
		$old[0] = ($new[0] + $new[3]) / 2;
		$old[1] = ($new[1] + $new[4]) / 2;
		$old[2] = ($new[2] + $new[5]) / 2;
		
		xform -ws -piv $old[0] $old[1] $old[2];
		}
	}	

else CenterPivot;


#283

VISUAL HISTORY

This MEL displays all the steps in creating a model if the history wasn’t deleted
I also added a timer to display each step in the modeling procedure.

ENJOY


 //*************************************
 // Main procedure & User Interface
 
 
 global proc vHistory()
 {
 	
 global string $qvhis[];
 $qvhis={};
 
 if (`window -q -ex HisWindow` == true) deleteUI HisWindow;
 window -w 250 -h 545 -s false -t "visual History v0.8b" -menuBar true HisWindow;
 
 menu -label "Refresh" -allowOptionBoxes false;
 menuItem -label "Refresh" -en true -c "vHistory";
 
 scrollLayout scr;  
 rowColumnLayout -numberOfColumns 2 -columnWidth 1 170 
 			 -columnWidth 2 50 ;
 
 global string $selected[];
 $selected=`ls -sl`;
 
 if (size($selected) > 0)
 {
 setAttr ($selected[0]+".v") 1;
 global string $hist[];
 $hist=`listHistory $selected[0]`;
 
 
 text -l "";
 text -l "";
 
 text -l " The Original";
 button -l "Restore" -w 80 -bgc 0.8 0.8 0.9 -c doRestore;
 
 text -l "";
 text -l "";
 
 separator;
 separator;
 
 
 text -l "";
 text -l "";
 
 
 text -l " History";
 text -l "List";
 
 text -l "";
 text -l "";
 
 global string $final;
 int $k=0;
 
 for ($h in $hist)
 {
 	string $type=`nodeType $h`;
 	if ($type != "mesh" && $type != "transformGeometry")
 	{
 		text -l (" "+$h);
 		string $c=("doView(\""+$h+"\")");
 		button -l "View" -w 80 -c $c;
 		if ($k==0)
 		{
 			$final=$h;
 			$k=1;
 		}
 		
 	}	
 	
 	
 	
 }
 text -l "";
 text -l "";
 
 separator;
 separator;
 
 
 text -l "";
 text -l "";
 
 text -l " Timer Show";
 button -l "Show" -w 80 -bgc 0.8 0.8 0.9 -c doShow;
 
 text -l " Pause in seconds :";
 intField -v 1 intf;
 
 
 
 text -l "";
 text -l "";
 
 separator;
 separator;
 
 text -l "";
 text -l "";
 
 text -l " Prepare Batch Render";
 button -l "Prepare" -w 80 -bgc 0.8 0.8 0.9 -c doBatch;
 
 text -l " Hold step, in frames :";
 intField -v 25 iframe;
 checkBoxGrp
 			 -numberOfCheckBoxes 1
 			 -label " Don't hide last step" -v1 1 chk;
 }
 else
 	text -l "NO OBJECT IS SELECTED";
 
 	
 showWindow HisWindow;
 window -e -w 250 -h 545 HisWindow;
 }
 
 //*******************************
 
 
 //********************************
 // Batch Prepare :
 
 global proc doBatch()
 {
 	global string $selected[];
 	global string $hist[];
 	int $iframe=`intField -q -v iframe`;
 	int $chk=`checkBoxGrp -q -v1 chk`;
 	
 	int $sz=size($hist);
 	
 	int $i=$sz-1;
 	string $newName;
 
 $j=1;
 
 while ($i >= 0)
 {
 	string $h=$hist[$i];
 	if (size($h)>0)
 	{
 		string $type=`nodeType $h`;
 		if ($type != "mesh" && $type != "transformGeometry")
 		{
 			doView($h);
 			string $result[];
 			
 			$result=`duplicate -rr`;
 			
 			$newName=`rename $result[0] ("step"+$j)`;
 			
 			if ($j!=1)
 			{
 				currentTime (($j-1)*$iframe);
 				setKeyframe -breakdown 0 -v 0 ($newName+".v");
 			}
 			currentTime (($j-1)*$iframe+1);
 			setKeyframe -breakdown 0 -v 1 ($newName+".v");
 		
 			currentTime (($j)*$iframe);
 			setKeyframe -breakdown 0 -v 1 ($newName+".v");
 
 			currentTime (($j)*$iframe+1);
 			setKeyframe -breakdown 0 -v 0 ($newName+".v");	
 
 			$j++;		
 		}
 	}
 	$i--;		
 }
 
 if ($chk==1)
 	setKeyframe -breakdown 0 -v 1 ($newName+".v");
 
 currentTime 1;
 doRestore();
 setAttr ($selected[0]+".v") 0;
 
 }
 
 //************************************
 
 
 
 //********************************
 // Timer show :
 
 global proc doShow()
 {
 	global string $selected[];
 	global string $hist[];
 	
 	int $t=`intField -q -v intf`;
 	
 	int $sz=size($hist);
 	
 	int $i=$sz-1;
 	
 
 
 
 while ($i >= 0)
 {
 	string $h=$hist[$i];
 	if (size($h)>0)
 	{
 		string $type=`nodeType $h`;
 		if ($type != "mesh" && $type != "transformGeometry")
 		{
 			doView($h);
 			refresh;
 			pause -sec $t;
 		}
 	}
 	$i--;		
 }
 
 
 doRestore();
 
 }
 
 //************************************
 
 
 
 
 //************************************
 //Method 1  (mesh connect)
 //Simple , history attribute connection .output or .outputGeometry to the shape's .inMesh 
 
 global proc doRestore2()
 {
 	global string $final;
 	doView($final);
 
 }
 
 
 
 global proc doView2(string $s)
 {
 	global string $selected[];
 	string $rel[]=`listRelatives $selected[0]`;
 	string $ats[]=`listAttr -c -hd -ro $s`;
 	for ($at in $ats)
 	{
 		string $sub=`substring $at 1 6`;
 		if ($sub=="output")
 		{
 			connectAttr -f ($s+"."+$at) ($rel[0]+".inMesh");
 			break;
 		}
 	}
 	print ($s+" is shown
");
 
 	
 }
 
 //************************************
 
 
 
 
 
 
 
 
 //************************************
 //Method 2  (undo)
 //General; not only meshs, keeps the original intact , deletes History and undo the delete actions . 
 
 
 global proc doRestore()
 {
 	global string $selected[];
 	global string $qvhis[];
 	setAttr ($selected[0]+".v") 1;
 	
 	if (size($qvhis)>0)
 		delete $qvhis;
 	
 	select -r $selected[0];
 
 	$qvhis={};
 	
 	
 }
 
 
 global proc doView(string $s)
 {
 
 	global string $hist[];
 	global string $selected[];
 	global string $qvhis[];
 	
 	setAttr ($selected[0]+".v") 1;
 	if (size($qvhis)>0)
 		delete $qvhis;
 	
 	undoInfo -state on -infinity on;
 	
 int $u=0;
 for ($h in $hist)
 {
 	if ($h != $s)
 	{
 		string $type=`nodeType $h`;
 		if ($type != "mesh" && $type != "transformGeometry")
 		{
 			delete $h;	
 			$u++;	
 		}	
 	}
 	else
 		break;
 }
 
 undoInfo -swf 0;
 $qvhis=`duplicate -rr $selected[0]`;
 $qvhis[0]=`rename $qvhis[0] ("history_level_"+$h)`;
 setAttr ($selected[0]+".v") 0;
 undoInfo -swf 1;
 
 int $i=0;
 while ($i<$u)
 {
 	$i++;
 	undo;
 }
 select -r $qvhis[0];
 
 
 }
 
 //************************************
 

#284

a small script i wrote making it easier to control the render stats for multiple objects without having to do it in the attribute spread sheet.

just save it as a mel file and call it with “multiObjRenderStatsCtrl”


  
  global proc multiObjRenderStatsCtrl(){
  
  if (`window -ex myUI`)
  	deleteUI myUI;
  
  window -t "Render Stats" 
  	-maximizeButton false
  	-minimizeButton false
  	-resizeToFitChildren true 
  	myUI;
  
  columnLayout -adjustableColumn 1;
  
  // ===================================chekBoxes
  
  checkBox -v 1 -al left -l "  CastShadows  " -cc "checkCastSh" castSh;
  checkBox -v 1 -al left -l "  ReceiveShadows  " -cc "checkReceiveSh" receiveSh;
  checkBox -v 1 -al left -l "  MotionBlur  " -cc "checkMotionBlur" mBlur;
  checkBox -v 1 -al left -l "  PrimaryVisibility  " -cc "checkPrimaryVis" primaryVis;
  checkBox -v 1 -al left -l "  SmoothShading  " -cc "checkSmoothShade" smoothShade;
  checkBox -v 1 -al left -l "  VisibleInReflections  " -cc "checkVisReflections" visReflections;
  checkBox -v 1 -al left -l "  VisibleInRefractions  " -cc "checkVisRefractions" visRefractions;
  checkBox -v 1 -al left -l "  DoubleSided  " -cc "checkDoubleSide" doubleSide;
  checkBox -v 1 -al left -l "  Opposite  " -cc "checkOpposite" opposite;
  
  
  showWindow myUI;
  
  }
  
  
  // ============================================================= Inicio castShadows
  
  proc checkCastSh(){
  string $sel[] = `ls -sl`;
  int $primeiro = `checkBox -query -value castSh`;
  
  if ($primeiro == 0){
  	for ($obj in $sel){
  		setAttr ($obj + ".castsShadows") 0;
  	}
  }
  
  else
  	for ($obj in $sel){
  		setAttr ($obj + ".castsShadows") 1;
  	}
  
  }
  
  // ============================================================= Fim castShadows
  
  // ============================================================= Inicio receiveShadows
  
  proc checkReceiveSh(){
  string $sel[] = `ls -sl`;
  int $segundo = `checkBox -query -value receiveSh`;
  
  if ($segundo == 0){
  	for ($obj in $sel){
  		setAttr ($obj + ".receiveShadows") 0;
  	}
  }
  
  else
  	for ($obj in $sel){
  		setAttr ($obj + ".receiveShadows") 1;
  	}
  
  }
  
  // ============================================================= Fim receiveShadows
  
  // ============================================================= Inicio motionBlur
  
  proc checkMotionBlur(){
  string $sel[] = `ls -sl`;
  int $terceiro = `checkBox -query -value mBlur`;
  
  if ($terceiro == 0){
  	for ($obj in $sel){
  		setAttr ($obj + ".motionBlur") 0;
  	}
  }
  
  else
  	for ($obj in $sel){
  		setAttr ($obj + ".motionBlur") 1;
  	}
  
  }
  
  // ============================================================= Fim motionBlur
  
  // ============================================================= Inicio primaryVisibility
  
  proc checkPrimaryVis(){
  string $sel[] = `ls -sl`;
  int $quarto = `checkBox -query -value primaryVis`;
  
  if ($quarto == 0){
  	for ($obj in $sel){
  		setAttr ($obj + ".primaryVisibility") 0;
  	}
  }
  
  else
  	for ($obj in $sel){
  		setAttr ($obj + ".primaryVisibility") 1;
  	}
  
  }
  
  // ============================================================= Fim primaryVisibility
  
  // ============================================================= Inicio smoothShading
  
  proc checkSmoothShade(){
  string $sel[] = `ls -sl`;
  int $quinto = `checkBox -query -value smoothShade`;
  
  if ($quinto == 0){
  	for ($obj in $sel){
  		setAttr ($obj + ".smoothShading") 0;
  	}
  }
  
  else
  	for ($obj in $sel){
  		setAttr ($obj + ".smoothShading") 1;
  	}
  
  }
  
  // ============================================================= Fim smoothShading
  
  
  // ============================================================= Inicio visibleInReflections
  
  proc checkVisReflections(){
  string $sel[] = `ls -sl`;
  int $sexto = `checkBox -query -value visReflections`;
  
  if ($sexto == 0){
  	for ($obj in $sel){
  		setAttr ($obj + ".visibleInReflections") 0;
  	}
  }
  
  else
  	for ($obj in $sel){
  		setAttr ($obj + ".visibleInReflections") 1;
  	}
  
  }
  
  // ============================================================= Fim visibleInReflections
  
  // ============================================================= Inicio visibleInRefractions
  
  proc checkVisRefractions(){
  string $sel[] = `ls -sl`;
  int $setimo = `checkBox -query -value visRefractions`;
  
  if ($setimo == 0){
  	for ($obj in $sel){
  		setAttr ($obj + ".visibleInRefractions") 0;
  	}
  }
  
  else
  	for ($obj in $sel){
  		setAttr ($obj + ".visibleInRefractions") 1;
  	}
  
  }
  
  // ============================================================= Fim visibleInRefractions
  
  // ============================================================= Inicio doubleSided
  
  proc checkDoubleSide(){
  string $sel[] = `ls -sl`;
  int $oitavo = `checkBox -query -value doubleSide`;
  
  if ($oitavo == 0){
  	for ($obj in $sel){
  		setAttr ($obj + ".doubleSided") 0;
  	}
  }
  
  else
  	for ($obj in $sel){
  		setAttr ($obj + ".doubleSided") 1;
  	}
  
  }
  
  // ============================================================= Fim doubleSided
  
  // ============================================================= Inicio opposite
  
  proc checkOpposite(){
  string $sel[] = `ls -sl`;
  int $nono = `checkBox -query -value opposite`;
  
  if ($nono == 0){
  	for ($obj in $sel){
  		setAttr ($obj + ".opposite") 0;
  	}
  }
  
  else
  	for ($obj in $sel){
  		setAttr ($obj + ".opposite") 1;
  	}
  
  }
  
  // ============================================================= Fim opposite
  
  
  

-sergio


#285

wow! I just discovered this thread!! :smiley:
Its from 2002 and still not dead ^^ cool thang

 ok want some snippets stuff from my shelf? :

//open folder containing the scene:

system ("explorer /select,\"" + toNativePath(`file -q -location`) + "\"");

// match position:

{
   	string $sel[] = `ls -sl -tr`;
   	if (size($sel) > 1)
   	{
   		float $pos[] = `xform -q -t -ws $sel[0]`;
   		float $rot[] = `xform -q -ro -ws $sel[0]`;
   		float $scl[] = getAttr ($sel[0] + ".scale");
   		$sel = stringArrayRemove({$sel[0]},$sel);
   		for ($obj in $sel)
   		{
   			setAttr ($obj + ".translate") $pos[0] $pos[1] $pos[2];
   			setAttr ($obj + ".rotate") $rot[0] $rot[1] $rot[2];
   			setAttr ($obj + ".scale") $scl[0] $scl[1] $scl[2];
   		}
   	}
   }

// match pivot

// match pivot
  {
  	string $sel[] = `ls -sl -tr`;
  	if (size($sel) > 1)
  	{
  		float $pPos[] = `xform -q -ws -rotatePivot $sel[0]`;
  		$sel = stringArrayRemove({$sel[0]},$sel);
  		for ($obj in $sel)
  			move -a $pPos[0] $pPos[1] $pPos[2] ($obj + ".scalePivot") ($obj + ".rotatePivot");
  	}
  }

// context sensitive delete history

if (size(`ls -sl`))
   	delete -ch;
   else
   {
   	delete -all -ch;
   	warning "whole construction history deleted !";
   }

you know you can select a code-snippet and drag it directly onto the shelf!!


#286

This is a MEL script to generate a patch of grass which I learnt in my class.

 proc string generateBlade(string $levelOfDetail, string $style) 
// change grass to blade and make local

{

// Declaration of variables

float $grassRadius = `rand 0.02 0.06`;

float $grassHeight;

float $grassCurl;

float $envelopeVal;

// Declaration of variable for subdivisionsY

float $value;

// Change height and bend values to accommodate user input.

switch($style)

{

case "short":

{

$grassHeight = `rand 0.4 0.8`;

$grassCurl = `rand 0 -.1`;

$envelopeVal = `rand 0.9 1.0`;

switch($levelOfDetail)

{

case "low":

$value = 1;

break;

case "medium":

$value = 3;

break;

case "high":

$value = 5;

break;

}

}

break;

case "normal":

{

$grassHeight = `rand 0.7 1.2`;

$grassCurl = `rand -0.25 -1.0`;

$envelopeVal = `rand 0.6 1.0`;

switch($levelOfDetail)

{

case "low":

$value = 3;

break;

case "medium":

$value = 5;

break;

case "high":

$value = 10;

break;

}

}

break;

case "long":

{

$grassHeight = `rand 1 1.6`;

$grassCurl = `rand -0.35 -1.25`;

$envelopeVal = `rand 0.5 1.0`;

switch($levelOfDetail)

{

case "low":

$value = 4;

break;

case "medium":

$value = 7;

break;

case "high":

$value = 11;

break;

}

}

break;

case "very long":

{

$grassHeight = `rand 2 3.5`;

$grassCurl = `rand -1 -1.5`;

$envelopeVal = `rand 0.5 0.85`;

switch($levelOfDetail)

{

case "low":

$value = 5;

break;

case "medium":

$value = 8;

break;

case "high":

$value = 13;

break;

}

}

break;

default:

{

warning ("Type " + $style + " is unknown. Using default settings.");

$grassHeight = `rand 0.7 1.2`;

$grassCurl = `rand -0.25 -1`;

$envelopeVal = `rand 0.6 1.0`;

switch($levelOfDetail)

{

case "low":

$value = 3;

break;

case "medium":

$value = 6;

break;

case "high":

$value = 10;

break;

}

}

break;

}

//Creation of Poly Cone

string $blades[] = `polyCone

-radius $grassRadius

-height $grassHeight

-subdivisionsX 3

-subdivisionsY $value

-subdivisionsZ 0

-axis 0 1 0

-texture 1

-constructionHistory off`;

// Bring the bottom of the cone to ground level

setAttr ($blades[0] + ".translateY") ($grassHeight* 0.5);

// harden the edges of cone

polySoftEdge

-angle 30

($blades[0] + ".e[0:59]")

;

// this can be done in the Maya interface with the cone selected and

// selecting Normals>Harden Edge

// The ".e[#:#] refers to the edge numbers ranging from 0 to 59

// go back to object mode

// and ensure the cone is selected

changeSelectMode -object;

select -replace $blades;

// make the blade thin;

setAttr ($blades[0] + ".scaleX") 0.25;

makeIdentity

-apply true

-translate true

-rotate true

-scale true

$blades[0];

makeIdentity

-apply false

-translate true

-rotate true

-scale true

$blades[0];

// Add the bend deformer, capture the name to move it

string $bend[] = `nonLinear

-type bend

-lowBound 0

-highBound 2

-curvature $grassCurl`

;

//$bend[1] stores the deformer's transformation info

//$bend[0] stores the deformer's deformation parameters

setAttr($bend[1] + ".ty") 0;

setAttr($bend[0] + ".envelope") $envelopeVal;

select -replace $blades;

delete -constructionHistory $blades;

return $blades[0];

// this will return the geometry's transform node of the cone created.

}

global proc generateGrass(string $levelOfDetail, string $style, int $density)

{

// Declare variables

string $createdGrass[];

//for loop to create multiple blades of grass

for($i=0;$i<$density;$i++)

{

$createdGrass[`size $createdGrass`] = `generateBlade $levelOfDetail $style`;

// Generate Random Values for translation and rotation

float $randomX = `rand -5 5`;

float $randomZ = `rand -5 5`;

float $randomRotate = `rand 0 360`;

// Assign the random values to the translate values

setAttr ($createdGrass[$i] + ".translateX") $randomX;

setAttr ($createdGrass[$i] + ".translateZ") $randomZ;

setAttr ($createdGrass[$i] + ".rotateY") $randomRotate;

if(`size $createdGrass` > 500)

{

string $united[] = `polyUnite $createdGrass`;

clear $createdGrass;

$createdGrass = $united;

flushUndo;

}

} // end of for loop

polyUnite -constructionHistory off $createdGrass;

// do a final combine

// select the created geometry

select -replace $createdGrass;

}

generateGrass low long 500;



#287

pretty slick script Ashram,
can you tell me what the ‘style 500’ attribute controls? What is the acceptable value range?

the script also throws up an error on line 382:
“No object matches name: pCone1”


#288

Hey guys!

 Here's my first "finished" script. Made it for a friend who doesn't like modeling at school because he doesn't have room for his reference images without dual monitors. 
 
 This creates a nice window allowing you to load in images which creates small thumbnails, then by clicking them it will load them larger below allowing you to zoom in on them and pan around. Also allows you to save out reference sets and load them back in later, as long as the reference image locations havn't changed. You can also delete unwanted thumbnails.
 
 The code is super clunky I know but it works. I started out thinking it would be super quick and ended up adding more stuff to it as I went. :shrug:

 REFERENCE WINDOW SCRIPT
 [b][http://www.jacobschieck.com/files/js_refWindow.mel](http://www.jacobschieck.com/files/js_refWindow.mel)[/b](right click -&gt; save as...)
 
 Hope this is useful to somebody. Enjoy!

#289

This would very helpful! Is there a way to do this already in Maya? it just seems like something that someone has to have thought about earlier…


#290

a little hackky but … maybe try:

proc string getStringArrayItem0(string $array[])
 {
 	return $array[0];
 }
 
 {
 	$camChildren = `listRelatives -c -type "transform" persp`;
 	if (size($camChildren))
 		delete $camChildren;
 	
 	string $curve1 = `curve -d 1 -p 0 0 -0.5 -p 0 0 0.5 -k 0 -k 1`;
 	string $curve2 = `curve -d 1 -p 0 0 -0.5 -p 0 0 0.5 -k 0 -k 1`;
 	$curve1 = getStringArrayItem0(`parent $curve1 persp`);
 	$curve2 = getStringArrayItem0(`parent $curve2 persp`);
 	setAttr ($curve1 + ".t")  0.5 0 -1.3;
 	setAttr ($curve2 + ".t") -0.5 0 -1.3;
 	setAttr ($curve1 + ".r") 90 0 0;
 	setAttr ($curve2 + ".r") 90 0 -180;
 	
 	setAttr ($curve1 + ".overrideEnabled") 1;
 	setAttr ($curve1 + ".overrideDisplayType") 2;
 	setAttr ($curve2 + ".overrideEnabled") 1;
 	setAttr ($curve2 + ".overrideDisplayType") 2;
 	
 	select $curve1 $curve2;
 	manipMoveContext -edit -mode 0 Move;
 }

then you can drag the x-axis to your desired position.
with a little math and connections you may do this more properly concerning the real resolutions and stuff … but I’m to lazy to find out for you :smiley:


#291

thanks for this and dgCopyKeys but they both are cut off at the bottom on OS X (Maya 2009). Thought you’d want to know.


#292

I never used mel before, but I just tried making that box made out of curves. pretty cool stuff.


#293

hi Guys,

I’m very new in this MEL Script, and not quite sure about it’s function (other than Maya GUI’s manipulation and animation).
Can MEL Script actually create an executable data?

thanks


#294

what MEL script? you mean new in MEL scripting at all?! :slight_smile:

With MEL you can do almost anything inside Maya. Maya is actually a collection of programmed parts that are all plugged together via MEL. Everything you look at in Mayas interface is somehow MEL scripted.

On the other Hand MEL is quite worthless outside of Maya. But actually if you manage MEL you can script any language :smiley:


#295

I see :slight_smile:
thanks for the explaining.

i was thinking to make an animated application ^^;


#296

I have a script which applies an NiMultishader to the selected object, creates an Occlusion color set in the CSE, occludes the mesh with all correct presets, and have a window which allows you to rebake with sliders to change the settings or modify the current bake set. But, I’m having trouble with what sounds like the most simplest step, selecting colorSet1 and the Occlusion color set and blend them both into a new blendedBakeSet using an “Add” polyColorBlendMode.

Here is my script

If anyone could help that person is amazing

// Create Warning Prompt

global proc checkboxPrompt(){

     // Dialog Form window.
     //
     string $form = `setParent -q`;

     // Layout Dialog Box
     
     formLayout -e -width 300 -height 300 $form;

     string $t = `text -l "DO NOT PRESS CTRL Z OR Z After Script, close this box"`;
 }

 layoutDialog -ui "checkboxPrompt";

{
//place objects selected into a variable

    $jrdSel=`ls -sl`;
 
 //Delete History, Freeze Transforms, Center Pivot to World
 DeleteHistory;
 delete -ch;
 FreezeTransformations;
 performFreezeTransformations(0);
 makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
 EnterEditMode;
 ctxEditMode;
 SnapToPoint;
 snapMode -point (!`snapMode -q -point`);
 updateSnapMasks;
 move 0 0 0 $jrdSel.scalePivot $jrdSel.rotatePivot ;
 SnapToPoint;

  // Create Occlusion Bake Set with presets
     {
     $bakeSetAO=`createBakeSet OcclusionSet vertexBakeSet`;

     setAttr OcclusionSet.colorMode 3;
     setAttr OcclusionSet.occlusionRays 256;
     setAttr OcclusionSet.occlusionFalloff 100;
     setAttr OcclusionSet.normalDirection 1;
     setAttr OcclusionSet.orthogonalReflection 1;
     setAttr OcclusionSet.bakeColor 1;
     setAttr OcclusionSet.bakeAlpha 0;
     setAttr -type "string" OcclusionSet.colorSetName "Occlusion";
 }

 // Creates Bake Set
 if ( `objExists initialTextureBakeSet` == 0 )
 {
    createBakeSet initialTextureBakeSet textureBakeSet;
 }

 if ( `objExists initialVertexBakeSet` == 0 )
 {
     createBakeSet initialVertexBakeSet vertexBakeSet;
 }

 // Assign the shape nodes to Occlusion
 for ( $eachObj in $jrdSel )
 {
     string $shape[]=`listRelatives -s $eachObj`;
     sets -forceElement OcclusionSet $shape[0];
 }

 // Bake selected Objects.
 select -r $jrdSel;
 catchQuiet ( `convertLightmapSetup  -camera persp -sh  -vm -showcpv` );

}

{
$jrdSel=ls -sl;
// Assign a NiMultiShader to a combined mesh .
//
string $myShader = shadingNode -asShader NiMultiShader;
string $NiMultiShader1SG = ($myShader + “NiMultiShader1SG”);
sets -renderable true -noSurfaceShader true
-empty -name $NiMultiShader1SG;
defaultNavigation -connectToExisting
-source $myShader
-destination $NiMultiShader1SG;

 select -r $jrdSel;
 sets -e -forceElement $NiMultiShader1SG;

{

$jrdSel=ls -sl;

if (window -exists myWindow) { deleteUI -window myWindow; }
window -rtf true -title “OcclusionReBake” myWindow;

columnLayout;

floatSliderGrp -dragCommand “findValues” -minValue 0 -maxValue 4 -label “Color Mode” -field true posCol;
floatSliderGrp -dragCommand “findValues” -minValue 1 -maxValue 256 -label “Occlusion Rays” -field true posRay;
floatSliderGrp -dragCommand “findValues” -minValue 0 -maxValue 100 -label “Occlusion Falloff” -field true posFal;

columnLayout -adjustableColumn true;
button -label “Bake” -c BatchBake;
button -label “Color Set Editor” -c “colorSetEditor”;
button -h 26 -w 80 -l “Modify Bake”
-c “colorSetEditCmd modify colorSetList”
-enable true
modifyButton;

showWindow myWindow;

proc findValues () {

float $myNumPosCol = floatSliderGrp -q -value "posCol";
float $myNumPosRay = floatSliderGrp -q -value "posRay";
float $myNumPosFal = floatSliderGrp -q -value "posFal";

print $myNumPosFal;
setAttr “OcclusionSet.colorMode” $myNumPosCol;
setAttr “OcclusionSet.occlusionRays” $myNumPosRay;
setAttr “OcclusionSet.occlusionFalloff” $myNumPosFal;

select -r $jrdSel;

}

HypershadeWindow;
colorSetEditor;
}
}


#297

Hi
I need to know if it is possible to connect MAYA with C#… I know it is a weird question but my boss is having a go at me cause I really do not know…

I think the answer is NO but still need to hear it from someone that has been doing this for longer than me…

If anyone can help please let me know.

Thanks.


#298

google is your friend:
http://www.google.com/search?&q=maya%20plugins%20with%20c%23

why posting this in “MEL scripts”?!?!? :surprised


#299

Because I need to know if it is possible to integrate mel and C#.


#300

Yea but for more than 6 years over 20 pages people in this thread discuss certain Mel Scripts.

I mean open up a new thread in the parent thread “Maya Programming” thats what its for! :smiley:

btw: for “mel” I can tell you: yes its pretty possible to do stuff with it in Maya ;]
But for C#: yea see the search there are guys talking about it. should work.