How to add a MEL script to the shelf:
1. Add the MEL script to Script Editor input section (as described above)
2. Select the MEL script (CTRL + A or click drag)
3. Middle mouse drag the selected scrip to your shelf
Monday, 16 April 2012
MM:Advanced Modeling HUD Script
//Nurbs Modeling HUD
//Author: Jason "BuZZ" Busby
//Date: 12/16/05
//USE AT YOUR OWN RISK!
//Note: This scipt, while not completely finished,
//is the very one used in the Dash Cunning videos of Adv. Modeling
if( `optionVar -exists "nurbsDisplayItem"`)
optionVar -iv "nurbsDisplayItem" 0;
if (!`HUD_Cleanup`)
HUD_Create;
global proc int HUD_Cleanup()
{
int $HUD_Exists = 0;
string $HUDs[] = {
"HUD_selected",
"HUD_spans",
"HUD_degree",
"HUD_minMaxU",
"HUD_minMaxV",
"HUD_Rebuild",
"HUD_Attach",
"HUD_Detach",
"HUD_InsertIsoparm",
"HUD_CVCurveTool",
"HUD_EPCurveTool"
};
for ($HUD_Num = 0; $HUD_Num < size($HUDs); $HUD_Num++)
{
if( `headsUpDisplay -exists $HUDs[$HUD_Num]`)
{
headsUpDisplay -remove $HUDs[$HUD_Num];
$HUD_Exists = 1;
}
}
return $HUD_Exists;
}
global proc HUD_Create()
{
$section = 0;
headsUpDisplay
-section $section
-block `headsUpDisplay -nextFreeBlock $section`
-blockSize "small"
-label "NURBS Selected: None"
-labelFontSize "small"
-labelWidth 100
-command "getNurbsAttr visTest"
-event "SelectionChanged"
-nodeChanges "attributeChange"
-visible false
HUD_selected;
headsUpDisplay
-section $section
-block `headsUpDisplay -nextFreeBlock $section`
-blockSize "small"
-label "Spans UV"
-labelFontSize "small"
-labelWidth 100
-command "getNurbsAttr spansUV"
-event "SelectionChanged"
-nodeChanges "attributeChange"
HUD_spans;
headsUpDisplay
-section $section
-block `headsUpDisplay -nextFreeBlock $section`
-blockSize "small"
-label "Degree UV"
-labelFontSize "small"
-labelWidth 100
-command "getNurbsAttr degreeUV"
-event "SelectionChanged"
-nodeChanges "attributeChange"
HUD_degree;
headsUpDisplay
-section $section
-block `headsUpDisplay -nextFreeBlock $section`
-blockSize "small"
-label "Min Max Range U"
-labelFontSize "small"
-labelWidth 100
-command "getNurbsAttr minMaxRangeU"
-event "SelectionChanged"
-nodeChanges "attributeChange"
HUD_minMaxU;
headsUpDisplay
-section $section
-block `headsUpDisplay -nextFreeBlock $section`
-blockSize "small"
-label "Min Max Range V"
-labelFontSize "small"
-labelWidth 100
-command "getNurbsAttr minMaxRangeV"
-event "SelectionChanged"
-nodeChanges "attributeChange"
HUD_minMaxV;
hudButton
-section $section
-b `headsUpDisplay -nextFreeBlock $section`
-vis 1
-l "Rebuild"
-bw 150
-bsh "roundRectangle"
-rc "HUDButtonRebuild()"
HUD_Rebuild;
hudButton -section $section
-b `headsUpDisplay -nextFreeBlock $section`
-vis 1
-l "Attach & Rebuild"
-bw 150
-bsh "roundRectangle"
-rc "HUDnurbsAttach()"
HUD_Attach;
hudButton -section $section
-b `headsUpDisplay -nextFreeBlock $section`
-vis 1
-l "Detach & Rebuild"
-bw 150
-bsh "roundRectangle"
-rc "HUDnurbsDetach()"
HUD_Detach;
hudButton -section $section
-b `headsUpDisplay -nextFreeBlock $section`
-vis 1
-l "Insert Isoparm"
-bw 150
-bsh "roundRectangle"
-rc "HUDinsertIsoparm()"
HUD_InsertIsoparm;
hudButton -section $section
-b `headsUpDisplay -nextFreeBlock $section`
-vis 1
-l "CV Curve Tool"
-bw 150
-bsh "roundRectangle"
-rc "HUDCVCurveTool()"
HUD_CVCurveTool;
hudButton -section $section
-b `headsUpDisplay -nextFreeBlock $section`
-vis 1
-l "EP Curve Tool"
-bw 150
-bsh "roundRectangle"
-rc "HUDEPCurveTool()"
HUD_EPCurveTool;
}
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
// Gets the nurbs attributes
global proc string getNurbsAttr ( string $dataType ) //$a
{
// List last selected object
string $selList[] = `ls -sl -tail 1 -dag -shapes`;
string $compList[] = `ls -hl -tail 1 -dag`;
string $objectType = "";
string $rVal;
if ( `size $selList` == 0 && `size $compList` > 0)
{
$selList[0] = $compList[0];
}
if (`size $selList` > 0)
$objectType = `nodeType $selList[0]`;
if (( `size $selList` == 0 ) || (( $objectType != "nurbsSurface" ) && ( $objectType != "nurbsCurve" )))
{
hideHUD;
return "";
}
///////////////////////////////////////////////////////////////
// NURBS SURFACES //
///////////////////////////////////////////////////////////////
if ( $objectType == "nurbsSurface" )
{
//if ( $dataType == "visTest" )
// return "";
if ( $dataType == "spansUV" )
{
float $spansU = `getAttr ( $selList[0] + ".spansU" )`;
float $spansV = `getAttr ( $selList[0] + ".spansV" )`;
if ($spansU < 10)
$rVal = (" " + $spansU + " " + $spansV); // 4 x 8 spaces
else
$rVal = (" " + $spansU + " " + $spansV); //4 x 6 spaces
headsUpDisplay -edit -label "Spans UV" HUD_spans;
}
if ( $dataType == "degreeUV" )
{
float $degreeU = `getAttr ( $selList[0] + ".degreeU" )`;
float $degreeV = `getAttr ( $selList[0] + ".degreeV" )`;
$rVal = (" " + $degreeU + " " + $degreeV);
headsUpDisplay -edit -label "Degree UV" HUD_degree;
}
if ( $dataType == "minMaxRangeU" )
{
float $minMaxRangeU[] = `getAttr ( $selList[0] + ".minMaxRangeU" )`;
string $minRangeU = $minMaxRangeU[0];
string $maxRangeU = $minMaxRangeU[1];
$rVal = (" " + $minRangeU + " " + $maxRangeU);
headsUpDisplay -edit -label "Min Max Range U" HUD_minMaxU;
}
if ( $dataType == "minMaxRangeV" )
{
float $minMaxRangeV[] = `getAttr ( $selList[0] + ".minMaxRangeV" )`;
string $minRangeV = $minMaxRangeV[0];
string $maxRangeV = $minMaxRangeV[1];
$rVal = (" " + $minRangeV + " " + $maxRangeV);
headsUpDisplay -edit -visible true HUD_minMaxV;
}
}
///////////////////////////////////////////////////////////////
// NURBS CURVES //
///////////////////////////////////////////////////////////////
else if ( $objectType == "nurbsCurve" )
{
if ( $dataType == "spansUV" )
{
int $spans = `getAttr ( $selList[0] + ".spans" )`;
$rVal = (" " + $spans);
headsUpDisplay -edit -label "Spans" HUD_spans;
}
if ( $dataType == "degreeUV" )
{
int $degree = `getAttr ( $selList[0] + ".degree" )`;
$rVal = (" " + $degree);
headsUpDisplay -edit -label "Degree" HUD_degree;
}
if ( $dataType == "minMaxRangeU" )
{
float $minMaxValue[] = `getAttr ( $selList[0] + ".minMaxValue" )`;
string $minValue = $minMaxValue[0];
string $maxValue = $minMaxValue[1];
$rVal = (" " + $minValue + " " + $maxValue);
headsUpDisplay -edit -label "Min Max Value" HUD_minMaxU;
}
if ( $dataType == "minMaxRangeV" )
{
$rVal = (" " + "-");
//headsUpDisplay -edit -visible false HUD_minMaxV;
}
}
showHUD($objectType);
return $rVal;
}
global proc hideHUD()
{
headsUpDisplay -edit -visible true HUD_selected;
headsUpDisplay -edit -visible false HUD_spans;
headsUpDisplay -edit -visible false HUD_degree;
headsUpDisplay -edit -visible false HUD_minMaxU;
headsUpDisplay -edit -visible false HUD_minMaxV;
hudButton -edit -visible false HUD_Rebuild;
hudButton -edit -visible false HUD_Attach;
hudButton -edit -visible false HUD_Detach;
hudButton -edit -visible false HUD_InsertIsoparm;
hudButton -edit -visible true HUD_CVCurveTool;
hudButton -edit -visible true HUD_EPCurveTool;
}
global proc showHUD(string $objectType)
{
if ((`headsUpDisplay -q -visible HUD_selected`) ||
(!`headsUpDisplay -q -visible HUD_minMaxV` && $objectType == "nurbsSurface") ||
(`headsUpDisplay -q -visible HUD_minMaxV` && $objectType == "nurbsCurve"))
{
headsUpDisplay -edit -visible false HUD_selected;
headsUpDisplay -edit -visible true HUD_spans;
headsUpDisplay -edit -visible true HUD_degree;
headsUpDisplay -edit -visible true HUD_minMaxU;
//headsUpDisplay -edit -visible true HUD_minMaxV;
hudButton -edit -visible true HUD_Rebuild;
hudButton -edit -visible true HUD_Attach;
hudButton -edit -visible true HUD_Detach;
//hudButton -edit -visible true HUD_InsertIsoparm;
hudButton -edit -visible false HUD_CVCurveTool;
hudButton -edit -visible false HUD_EPCurveTool;
if ($objectType == "nurbsSurface")
{
print ("Making visible! Surfaces!\n");
//We have a SURFACES selected, let's show a few things...
headsUpDisplay -edit -visible true HUD_minMaxV;
hudButton -edit -visible true HUD_InsertIsoparm;
}
else
{
//We have a CURVE selected, let's not show a few things...
headsUpDisplay -edit -visible false HUD_minMaxV;
hudButton -edit -visible false HUD_InsertIsoparm;
}
}
}
global proc HUDButtonRebuild()
{
string $selList[] = `ls -sl -tail 1 -dag`;
if ( size ($selList) < 1 )
{
print "No objects selected\n";
return;
}
if ( `nodeType $selList[0]` == "nurbsSurface" )
RebuildSurfacesOptions;
else if ( `nodeType $selList[0]` == "nurbsCurve" )
RebuildCurveOptions;
}
global proc HUDnurbsAttach()
{
//string $selList[] = `ls -sl -tail 1 -dag`;
string $SurfacesToAttach[] = `ls -sl -objectsOnly`;
if (size($SurfacesToAttach) == 2)
{
//Get list of objects we will be dealing with
string $parentOfShape[] = `listRelatives -fullPath -parent $SurfacesToAttach[0]`;
string $newTransform = $parentOfShape[0];
if ( `nodeType $SurfacesToAttach[0]` == "nurbsSurface" )
{
//Attach constists of: Attaching - Rebuild with CVs - Delete History - Component Mode: Isoparms
//Attach the two selected NURBS Shapes
attachSurface -ch 1 -rpo 1 -kmk 1 -m 1 -bb 0.5 -bki 0 -p 0.1;
setAttr ($SurfacesToAttach[1] + ".io") true;
//Delete History
select -r $newTransform;
DeleteHistory;
//Rebuild with CVs - Spans: 0 to #Spans
rebuildSurface
-ch 1
-rpo 1
-rt 0
-end 1
-kr 2
-kcp 1
-kc 0
-su 4
-du 3
-sv 4
-dv 3
-tol 0.01
-fr 0
-dir 2;
select -r $newTransform;
}
else if ( `nodeType $SurfacesToAttach[0]` == "nurbsCurve" )
{
//Attach constists of: Attaching - Rebuild with CVs - Delete History
attachCurve -ch 1 -rpo 1 -kmk 1 -m 1 -bb 0.5 -bki 0 -p 0.1;
setAttr ($SurfacesToAttach[1] + ".io") true;
//Delete History
select -r $newTransform;
DeleteHistory;
}
}
}
global proc HUDnurbsDetach()
{
string $SurfacesToAttach[] = `ls -sl -objectsOnly`;
if (size($SurfacesToAttach) == 1)
{
//Get list of objects we will be dealing with
string $parentOfShape[] = `listRelatives -fullPath -parent $SurfacesToAttach[0]`;
string $newTransform = $parentOfShape[0];
if ( `nodeType $SurfacesToAttach[0]` == "nurbsSurface" )
{
//Detatch everything that needs to be detached
string $surfaces[]= `detachSurface -ch 1 -rpo 1`;
//Loop through all surfaces, rebuild and delete history
for ($i = 0; $i < size($surfaces) - 1; $i++)
{
select $surfaces[$i];
rebuildSurface
-ch 1
-rpo 1
-rt 0
-end 1
-kr 2
-kcp 1
-kc 0
-su 4
-du 3
-sv 4
-dv 3
-tol 0.01
-fr 0
-dir 2;
DeleteHistory;
}
//
for ($i = 0; $i < size($surfaces) - 1; $i++)
{
select -tgl $surfaces[$i];
}
selectMode -component;
selectType
-cv 0
-vertex 0
-subdivMeshPoint 0
-latticePoint 0
-particle 0
-editPoint 0
-curveParameterPoint 0
-surfaceParameterPoint 0
-puv 0
-polymeshEdge 1
-subdivMeshEdge 1
-isoparm 1
-surfaceEdge 1
-surfaceFace 0
-springComponent 1
-facet 0
-subdivMeshFace 0
-hull 0
-rotatePivot 0
-scalePivot 0
-jointPivot 0
-selectHandle 0
-localRotationAxis 0
-imagePlane 0;
}
else if ( `nodeType $SurfacesToAttach[0]` == "nurbsCurve" )
{
//Detach constists of: Detaching - Rebuild with CVs - Delete History
detachCurve -ch 1 -cos on -rpo 1;
//Delete History
select -r $newTransform;
DeleteHistory;
}
}
}
global proc HUDinsertIsoparm()
{
//string $selList[] = `ls -sl -tail 1 -dag`;
string $SurfacesToAttach[] = `ls -sl -objectsOnly`;
if (size($SurfacesToAttach) == 1)
{
//Get list of objects we will be dealing with
string $parentOfShape[] = `listRelatives -fullPath -parent $SurfacesToAttach[0]`;
string $newTransform = $parentOfShape[0];
if ( `nodeType $SurfacesToAttach[0]` == "nurbsSurface" )
{
//Insert Isoparm
insertKnotSurface -ch 1 -nk 1 -add 1 -ib 0 -rpo 1;
//Delete History
select -r $newTransform;
DeleteHistory;
//Rebuild with CVs - Spans: 0 to #Spans
rebuildSurface
-ch 1
-rpo 1
-rt 0
-end 1
-kr 2
-kcp 1
-kc 0
-su 4
-du 3
-sv 4
-dv 3
-tol 0.01
-fr 0
-dir 2;
select -r $newTransform;
}
}
}
global proc HUDCVCurveTool()
{
CVCurveTool;
}
global proc HUDEPCurveTool()
{
EPCurveTool;
}
Subscribe to:
Posts (Atom)