Thanks for the advice
MEL scripts
Hi,
thanks for this great thread!
I have some MEL scripts that I used on my projects. They are now cleaned up and uploaded on my site, under downloads section, so you can freely use them.
www.deform.rs
- Change render stats on multiple objects, included with a layering override.
- Toggle Lock/Hide on transform channel quickly and easily
- Duplicate objects along a particle shape, useful for environment trees etc…
I guess there are a lot of similar tools around the net, but I prefer writing my own tools when facing a problem, so that is how I got to these.
All of the scripts have a UI for easier use, and the info about installation/starting is included in the script file.
I hope you will have some benefit from them, regards to all and keep it up!!
Dejan Ivanovic
hello, i want to make some objects floating in space and i dont know how can i do this. so can anyone help me making an object move free on the 3 axis very slow. i want to do this because i want to control the distances between the object is moving and the speed also.
thanks.
if you don’t have a mel script for this thread, why don’t you open a new thread for your question?
did’t post a script as well
but I might have something:
// hides the menubars on the panels under the cursor
// on the modelpanel 4 is also shows/hides the darn icon bar
{
$thisPanel = `getPanel -wf`;
$menuBarvis= `panel -q -menuBarVisible $thisPanel`;
if ($thisPanel == "modelPanel4")
{
if ($menuBarvis)
layout -e -visible false -height 1 formLayout72;
else
layout -e -visible true -height 20 formLayout72;
}
panel -e -menuBarVisible (!$menuBarvis) $thisPanel;
}
I’m always longing for ways to get more space in Maya… :]
Simple spiral creator. Very basic. I’m still learning. I did this mainly to help understand UI construction better.
global proc OptionMenu_RemoveItems(string $optionMenu)
{
int $itemsCount = optionMenu -q -ni $optionMenu
;
if($itemsCount == 0)
{
//do error handling
}
else
{
int $i;
for($i=$itemsCount; $i>0; $i–)
{
optionMenu -e -sl $i $optionMenu;
string $menuItem = (optionMenu -q -v $optionMenu
+ “" + $optionMenu);
deleteUI $menuItem;
}
}
}
global proc OptionMenu_AddItems(string $items[], string $optionMenu)
{
int $itemsCount = size $items
;
if($itemsCount == 0)
{
//do error handling
}
else
{
int $i;
for($i=0; $i<$itemsCount; $i++)
{
menuItem -l $items[$i] -p ($optionMenu) -ann “” ($items[$i] + "” + $optionMenu);
}
}
}
Here is a little MEL script that I wrote for easily creating a deformable ribbon setup. User have the ability to change the length, width, number of joints (UV Span)…
Enjoy !
Hello All
I,m feeling confuse about Arrays.I know that arrays are 0 based & it’s first element is 0,second 1 & so on. But there is a one command in maya called stringArrayRemove.It requires two arrays.One Syntax is Confusing me.Actually,I write that: string $allCameras[] = listCameras
;
// Result: top,pers,front,side //
string $removeThis[1] = {“pers”};
// Result: pers //
string $result[] = stringArrayRemove ($removeThis, $allCameras[]);
// Result: top,front,side //
[b]This Syntax is confusing me : string $removeThis[1] = {“pers”};
I’ve understood everything,but when I declare 0 or 2 or 3 or another number in [1] ,then it works same,if I don’t declare nothing in [ ] , then the result is same.So why we declare 1 in [ ].I know that “stringArrayRemove” wants two Array.But without declaring or declaring another value in [ ] it works same.Specially,I felt more confusion when I declare number 0 like this [ 0 ] it’s meaning that it holds one Item,not Two (according to me).then it work same like declaring [ 1 ]. But Command called “stringArrayRemove” wants two Arrays,then why [ 0 ] works same.
What’s the Reasion Behind this : string $removeThis[1] = {“pers”};
[/b]
PLEASE HELP ME!
Thanks & Warm Regards
Rajat Chauhan
you can declare the lenght of the array in the []. So if you know that your array will have 3 elements like for a translation for instance you may declare it: float $pos[3]. MEL will automatically extend the array if you stuff more into it. But this way you can safe memory and processing time.
Of course if you don’t do thousands of loops you can trustfully ignore this feature. But IF you do and you have like hundreds of entries MEL has to extend the array over and over again which can cost valuable time.
this:
string $result[] = stringArrayRemove ($removeThis, $allCameras[]);
actually shouldn’t work because of the empty [] ^, huh?
and you can also have this inline:
string $allCameras[] = stringArrayRemove({“persp”},listCameras
);
and pls: next time just open a new thread for problems like this. This one is supposed to have mel scripts posted into it. Which I have to admit I’m lacking this time as well. Mea culpa. next time.:shrug:
Interesting thread.
Here’s a little widget I use for rigging. Creates a locator at center of the bounding box of selected objects. Great for laying out guide locators when rigging. For example, just select the edge loop or vertices for an elbow to get the optimal position for elbow joints, etc.
global proc refLoc()
{
float $bBox[] = `exactWorldBoundingBox`;
float $coordinateX = $bBox[0] - (($bBox[0] - $bBox[3]) * .5);
float $coordinateY = $bBox[1] - (($bBox[1] - $bBox[4]) * .5);
float $coordinateZ = $bBox[2] - (($bBox[2] - $bBox[5]) * .5);
spaceLocator -p $coordinateX $coordinateY $coordinateZ;
CenterPivot;
};
refLoc;
Hello,ppl plz help me here.i have one sphere at (0,0,0) now i want to move my sphere in clock wise and anticlockwise with the radius of 3 unit.plz i want to learn how to do this using expression, no with the manual like motion path and etc.
and if i get control over speed also then is will bonus for me.Thank you.
hello reply plz,how to move sphere in clockwise & anti clock wise with give radius.using expression
Tweak script:
Takes the selection of objects and applies random adjustments to the rotate, translate, or scale. This is the first version, so it could use some optimizing I’m sure, but it works
proc tweak(string $direction, float $maxAmount, string $ctx){
string $eachDir[];
string $eachCtx[];
float $rand;
string $sel[] = `ls -sl`;
$eachDir = stringToStringArray($direction, ",");
$eachCtx = stringToStringArray(tolower($ctx), ",");
if(0 == size($eachCtx)){
$rand = rand($maxAmount * -1, $maxAmount);
for($object in $sel){
print("Setting the one attr:" + $ctx + "
");
}
}else{
string $attr;
for($object in $sel){
$rand = rand($maxAmount * -1, $maxAmount);
for($direction in $eachDir){
for($cx in $eachCtx){
//print("Must move " + $object + " attribute '" + $cx + "' in the " + $direction + "
");
switch($cx){
case "t":
$attr = "translate";
break;
case "r":
$attr = "rotate";
break;
case "s":
$attr = "scale";
break;
}
//setAttr object.attributeX amount
setAttr($object + "." + $attr + $direction) $rand;
}
}
}
}
}
tweak("X,Y,Z", 10, "r,s");
There’s been a few times building walls or something similar where I just needed a hint of variety.
i thought id share this that i wrote last night, converts an edge loop to nurbs curve, wont work if the edge loop crosses over it self
/*------------------------------*\
creates a 3 degree nurbs curve
along the selected edge loop
note: will not work if loop
crosses over it's self
by james drew
\*------------------------------*/
global proc edgeLoopToWire(){
$edges = `ls -sl -fl`;
string $verts[];
vector $xyz[];
string $sortedVerts[];
for ($edge in $edges)
{
$verts[size($verts)] = stringArrayToString(filterExpand("-ex", 1, "-sm", 31, polyListComponentConversion("-tv", $edge)), " ");
}
//now to sort
string $sortedVerts[] = stringToStringArray($verts[0], " ");
stringArrayRemoveAtIndex(0, $verts);
string $vertBuffer[] = $verts;
for ($each in $verts)
{
for ($vert in $vertBuffer)
{
$vtxs = stringToStringArray($vert, " ");
if ($vtxs[0] == $sortedVerts[size($sortedVerts) -1])
{
$sortedVerts[size($sortedVerts)] = $vtxs[1];
$vertBuffer = stringArrayRemoveExact(stringToStringArray($vert, ""), $vertBuffer);
break;
}
else if ($vtxs[1] == $sortedVerts[size($sortedVerts) -1])
{
$sortedVerts[size($sortedVerts)] = $vtxs[0];
$vertBuffer = stringArrayRemoveExact(stringToStringArray($vert, ""), $vertBuffer);
break;
}
else if ($vtxs[0] == $sortedVerts[0])
{
stringArrayInsertAtIndex(0, $sortedVerts, $vtxs[1]);
$vertBuffer = stringArrayRemoveExact(stringToStringArray($vert, ""), $vertBuffer);
break;
}
else if ($vtxs[1] == $sortedVerts[0])
{
stringArrayInsertAtIndex(0, $sortedVerts, $vtxs[0]);
$vertBuffer = stringArrayRemoveExact(stringToStringArray($vert, ""), $vertBuffer);
break;
}
}
}
//verts are now sorted
string $createCurve = "curve -d 3 ";
for ($vert in $sortedVerts)
{
$pnt = pointPosition($vert);
$createCurve = ($createCurve + "-p " + $pnt[0] + " " + $pnt[1] + " " + $pnt[2] + " ");
}
$curve = `eval $createCurve`;
//if curve is a loop sealit it up
if ($sortedVerts[0] == $sortedVerts[size($sortedVerts)-1])
closeCurve -ch 0 -ps 2 -rpo 1 -bb 0.5 -bki 1 -p 0.1 $curve;
select $curve;
}