insertIsoparmThis is a featured page

/* insertiso.mel V2.1
This script may be freely distributed. Modify at your own risk.
Original Author: Dirk Bialluch <DirkBi@Software2000.de>
Enhanced by: Bryan Ewert <ewertb@cadvision.com>
Continued by: Dirk Bialluch
Creation Date: 15.09.98
Last Update: 20.06.99
DESCRIPTION:
This script creates a UI that lets you to select and insert isoparms on
any selected nurbs surface. UI settings are stored as soon as you execute
a insert function.
U/V Isoparm Slider
Use these slider to select the isoparms in u and v direction.
Snap
Enable snapping
Snap Value
Set the snap increment value. A snap value of 0.1 will constrain
the isoparm selection to 0.0, 0.1, 0.2, ...
UV Snap Value Info
Since the selection slider will not show the constrained snap value
this fields represent the current snap value.
Number of Knots
Set the number of knots to insert at the selected position.
Mirror
Enable mirror selection. This function will select an additional
isoparm at the opposite surface side.
Display Isoparm
Toggle the display of isoparms in u and v direction.
Update View
Force a manual view update. This is useful when you have already
brought the selection slider into position and select new nurbs
surfaces, that will not show the selected isoparms automatically.
Display Mode
`Fixed` will always show both isoparms, while `Slider` will show
the isoparm you are currently adjusting with the selection slider.
Both functions are dependent on the `Display Isoparm` settings.
View Refresh while dragging slider
Enable this function to refresh the view panel while you drag the
selection slider. When you enable this function the first time, a
warning is displayed. While it is easier to adjust the isoparm
position with this function enabled you may notice a slowdown on
complex models or many selected surfaces and you must keep in mind
that every single slider drag will be stored on the undo stack
since Maya notices a selection change.
Insert U/V/UV Isoparm
Press one of the buttons to execute the tool and insert an isoparm
in u, v or both directions.

HISTORY:
V2.1 - isoparm display will now update correctly when you type and
confirm values in the float field
- detached surfaces will now be handled properly
- slider range set to fixed value (0 - 1) allowing selection of
multiple surfaces
- added toggle for view update while dragging a slider due to undo
buffer and performance problems
- display toggle for both isoparm directions
- snap value
- mirror u & v direction
- store UI values
- set number of knots to insert
*/
//
// create UI
//
global proc insertIsoparm ()
{
if ((`window -exists ui_insertiso`) == true)
deleteUI ui_insertiso;
window -maximizeButton false -resizeToFitChildren true
-title "Insert Isoparm V2.1" -iconName "Insert Isoparm" ui_insertiso;
columnLayout -adjustableColumn true;
floatSliderGrp
-label "U Isoparm"
-field true
-precision 3
-sliderStep .01
-maxValue 1
-changeCommand "ii_insert 5"
ii_uSlider;
floatSliderGrp
-label "V Isoparm"
-field true
-precision 3
-sliderStep .01
-maxValue 1
-changeCommand "ii_insert 6"
ii_vSlider;
separator -h 10;
rowLayout
-numberOfColumns 3
-columnAttach 1 "right" 10
-columnWidth 1 140
-columnWidth 2 80;
text -label "Snap";
checkBox
-align "left"
-label "Enable"
-value false
-changeCommand "ii_insert 0"
ii_snapping;
text
-label ""
ii_snapInfo;
setParent ..;
floatSliderGrp
-label "Snap"
-field true
-precision 3
-sliderStep .05
-minValue .001
-maxValue .5
-value .25
-changeCommand "ii_insert 0"
ii_snapValue;
rowLayout
-numberOfColumns 4
-columnAttach 1 "right" 10
-columnWidth 1 140
-columnWidth 2 80
-columnWidth 3 90
ii_snapInfo;
text -label "UV Snap Value";
floatField
-w 80
-precision 3
-editable false
ii_uSnapInfo;
floatField
-w 80
-precision 3
-editable false
ii_vSnapInfo;
text -label "Info";
setParent ..;
separator -h 10;
radioButtonGrp
-numberOfRadioButtons 3
-label "Number of Knots"
-cw 1 140
-cw 2 50
-cw 3 50
-labelArray3 "1" "2" "3"
-select 1
-cc "ii_insert 0"
ii_knots;
separator -h 10;
rowLayout
-numberOfColumns 2
-columnAttach 1 "right" 10
-columnWidth 1 140;
text -label "Mirror";
checkBox
-align "left"
-label "Enable"
-value false
-changeCommand "ii_insert 0"
ii_mirror;
setParent ..;
separator -h 10;
rowLayout
-numberOfColumns 4
-columnAttach 1 "right" 10
-columnWidth 1 140
-columnWidth 2 45
-columnWidth 3 71;
text -label "Display Isoparm";
checkBox
-align "left"
-label "U"
-value true
-changeCommand "ii_insert 0"
ii_uDisplay;
checkBox
-align "left"
-label "V"
-value true
-changeCommand "ii_insert 0"
ii_vDisplay;
button
-w 128
-align "center"
-label "Update View"
-command "ii_insert 0"
ii_update;
setParent ..;
radioButtonGrp
-numberOfRadioButtons 2
-label "Display Mode"
-cw 1 140
-cw 2 70
-labelArray2 "Fixed" "Slider"
-select 1
-cc "ii_insert 0"
ii_displayMode;
separator -h 10;
rowLayout
-numberOfColumns 2
-columnAttach 1 "right" 10
-columnWidth 1 140;
text -label "View Refresh";
checkBox
-align "left"
-label "While dragging slider"
-value false
-changeCommand "ii_insert 4"
ii_viewRefresh;
setParent ..;
separator -h 10;
rowLayout
-numberOfColumns 3
-columnWidth 1 128
-columnWidth 2 128;
button
-w 128
-align "center"
-label "Insert U Isoparm"
-command "ii_insert 1"
ii_uButton;
button
-w 128
-align "center"
-label "Insert V Isoparm"
-command "ii_insert 2"
ii_vButton;
button
-w 128
-align "center"
-label "Insert UV Isoparm"
-command "ii_insert 3"
ii_uvButton;
setParent ..;
// restore UI settings
if (`optionVar -exists ii_uSlider`)
floatSliderGrp -e -value `optionVar -q ii_uSlider` ii_uSlider;
if (`optionVar -exists ii_vSlider`)
floatSliderGrp -e -value `optionVar -q ii_vSlider` ii_vSlider;
if (`optionVar -exists ii_snapValue`)
floatSliderGrp -e -value `optionVar -q ii_snapValue` ii_snapValue;
if (`optionVar -exists ii_snapping`)
checkBox -e -value `optionVar -q ii_snapping` ii_snapping;
if (`optionVar -exists ii_mirror`)
checkBox -e -value `optionVar -q ii_mirror` ii_mirror;
if (`optionVar -exists ii_uDisplay`)
checkBox -e -value `optionVar -q ii_uDisplay` ii_uDisplay;
if (`optionVar -exists ii_vDisplay`)
checkBox -e -value `optionVar -q ii_vDisplay` ii_vDisplay;
if (`optionVar -exists ii_viewRefresh`)
checkBox -e -value `optionVar -q ii_viewRefresh` ii_viewRefresh;
if (`optionVar -exists ii_knots`)
radioButtonGrp -e -select `optionVar -q ii_knots` ii_knots;
if (`optionVar -exists ii_displayMode`)
radioButtonGrp -e -select `optionVar -q ii_displayMode` ii_displayMode;
ii_selectionWatcher;
ii_insert 0;
showWindow ui_insertiso;
scriptJob -parent ui_insertiso -event "SelectionChanged" ii_selectionWatcher;
}

//
// subroutines ******************************************************************************
//
proc string rootNode( string $object )
{
string $buffer[];
tokenize $object "." $buffer;
return $buffer[0];
}
proc string getShape( string $node )
{
string $shape[] = `listRelatives -shapes $node`;
if ( size($shape) )
return $shape[0];
else
return $node;
}
global proc ii_selectionWatcher()
{
int $uiState = 0;
string $objList[] = `filterExpand -sm 10`;

if (size($objList))
$uiState++;
button -e -enable $uiState ii_uButton;
button -e -enable $uiState ii_vButton;
button -e -enable $uiState ii_uvButton;
}

proc ii_insertUV (string $isoparm, string $object, int $mirror, float $uv, float $uvMirror)
{
int $knots = `radioButtonGrp -q -select ii_knots`;
insertKnotSurface -ch 1 -nk $knots -add 1 -rpo 1 ($object + "." + $isoparm + "[" + $uv + "]");
if ($mirror)
insertKnotSurface -ch 1 -nk $knots -add 1 -rpo 1 ($object + "." + $isoparm + "[" + $uvMirror + "]");
}

//
// main procedure
//
global proc ii_insert (int $function)
{
// store UI settings
optionVar -floatValue ii_uSlider `floatSliderGrp -q -value ii_uSlider`;
optionVar -floatValue ii_vSlider `floatSliderGrp -q -value ii_vSlider`;
optionVar -floatValue ii_snapValue `floatSliderGrp -q -value ii_snapValue`;
optionVar -intValue ii_snapping `checkBox -q -value ii_snapping`;
optionVar -intValue ii_mirror `checkBox -q -value ii_mirror`;
optionVar -intValue ii_uDisplay `checkBox -q -value ii_uDisplay`;
optionVar -intValue ii_vDisplay `checkBox -q -value ii_vDisplay`;
optionVar -intValue ii_viewRefresh `checkBox -q -value ii_viewRefresh`;
optionVar -intValue ii_knots `radioButtonGrp -q -select ii_knots`;
optionVar -intValue ii_displayMode `radioButtonGrp -q -select ii_displayMode`;
global int $ii_uvSliderDisplay;
string $objList[] = `filterExpand -ex true -sm 10`;
select -clear;
// let's avoid those annoying "Some items cannot be..." warnings
global string $gSelect;
setToolTo $gSelect;
// get ui values
float $uSlider = `floatSliderGrp -q -value ii_uSlider`;
float $vSlider = `floatSliderGrp -q -value ii_vSlider`;
int $uDisplay = `checkBox -q -value ii_uDisplay`;
int $vDisplay = `checkBox -q -value ii_vDisplay`;
float $snapValue = `floatSliderGrp -q -value ii_snapValue`;
int $mirror = `checkBox -q -value ii_mirror`;
int $displayMode = `radioButtonGrp -q -select ii_displayMode`;
// adjust isoparm position when snapping is enabled
if (`checkBox -q -value ii_snapping`)
{
$uSlider = trunc (($uSlider + $snapValue / 2) / $snapValue) * $snapValue;
if ($uSlider > 1)
$uSlider = int($uSlider / $snapValue) * $snapValue - $snapValue;
$vSlider = trunc (($vSlider + $snapValue / 2) / $snapValue) * $snapValue;
if ($uSlider > 1)
$vSlider = int($vSlider / $snapValue) * $snapValue - $snapValue;
// set UI values
floatField -e -value $uSlider ii_uSnapInfo;
floatField -e -value $vSlider ii_vSnapInfo;
float $info1 = int(($snapValue + .0005) * 1000); // get .xxx rounded
float $info2 = int(($snapValue + .00025) * 2000); // get .xxx rounded
$info1 = $info1 / 1000;
$info2 = $info2 / 1000;
text -e -label ("(0, " + $info1 + ", " + $info2 + ", ...)") ii_snapInfo;
}
// adjust UI when snapping is enabled/disabled
int $state = 0;
if (`checkBox -q -value ii_snapping`)
$state = 1;
rowLayout -e -enable $state ii_snapInfo;
floatSliderGrp -e -enable $state ii_snapValue;
text -e -enable $state ii_snapInfo;
// adjust drag update
string $dState = "";
if (`checkBox -q -value ii_viewRefresh`)
$dState = "ii_insert 0";
floatSliderGrp -e -dragCommand $dState ii_uSlider;
floatSliderGrp -e -dragCommand $dState ii_vSlider;
switch ($function)
{
case 4:
if (`checkBox -q -value ii_viewRefresh`)
{
warning "This feature will have impact on the undo buffer and performance.";
checkBox -e -changeCommand "ii_insert 0" ii_viewRefresh; // disable message once displayed
}
break;
case 5:
$ii_uvSliderDisplay = 0; // display u isoparm when dragging u slider
break;
case 6:
$ii_uvSliderDisplay = 1; // display v isoparm when dragging v slider
break;
}
int $count;
for ($count; $count < size($objList); $count++)
{
// get shape
string $shape = getShape(rootNode($objList[$count]));
$minValueU = `getAttr ($shape + ".minValueU")`;
$maxValueU = `getAttr ($shape + ".maxValueU")`;
$minValueV = `getAttr ($shape + ".minValueV")`;
$maxValueV = `getAttr ($shape + ".maxValueV")`;
// calculate uv position
float $u= $uSlider * ($maxValueU - $minValueU) + $minValueU;
float $v= $vSlider * ($maxValueV - $minValueV) + $minValueV;
float $uMirror= (1 - $uSlider) * ($maxValueU - $minValueU) + $minValueU;
float $vMirror= (1 - $vSlider) * ($maxValueV - $minValueV) + $minValueV;
// select isoparms and nurbs geometry
select -add $objList[$count];
if ($uDisplay && ($displayMode == 1 || ($displayMode == 2 && $ii_uvSliderDisplay == 0)))
{
select -add ($objList[$count] + ".u[" + $u + "]");
if ($mirror)
select -add ($objList[$count] + ".u[" + $uMirror + "]");
}
if ($vDisplay && ($displayMode == 1 || ($displayMode == 2 && $ii_uvSliderDisplay == 1)))
{
select -add ($objList[$count] + ".v[" + $v + "]");
if ($mirror)
select -add ($objList[$count] + ".v[" + $vMirror + "]");
}
switch ($function)
{
// insert u isoparm
case 1:
if ($uSlider == 0 || $uSlider == 1)
warning "Cannot insert u isoparm at surface edge";
else
ii_insertUV
u // direction (uv)
$objList[$count] // nurbs shape name
$mirror // mirror enabled ?
$u // u or v value
$uMirror; // u or v mirror value
break;
// insert v isoparm
case 2:
if ($vSlider == 0 || $vSlider == 1)
warning "Cannot insert v isoparm at surface edge";
else
ii_insertUV
v // direction (uv)
$objList[$count] // nurbs shape name
$mirror // mirror enabled ?
$v // u or v value
$vMirror; // u or v mirror value
break;
// insert u & v isoparm
case 3:
if ($uSlider == 0 || $uSlider == 1)
warning "Cannot insert u isoparm at surface edge";
else
ii_insertUV
u // direction (uv)
$objList[$count] // nurbs shape name
$mirror // mirror enabled ?
$u // u or v value
$uMirror; // u or v mirror value
if ($vSlider == 0 || $vSlider == 1)
warning "Cannot insert v isoparm at surface edge";
else
ii_insertUV
v // direction (uv)
$objList[$count] // nurbs shape name
$mirror // mirror enabled ?
$v // u or v value
$vMirror; // u or v mirror value
break;
}
}
}
// end of script


gilakos
gilakos
Latest page update: made by gilakos , Sep 18 2006, 3:37 PM EDT (about this update About This Update gilakos Edited by gilakos

1874 words added

view changes

- complete history)
Keyword tags: None (edit keyword tags)
More Info: links to this page

Anonymous  (Get credit for your thread)


There are no threads for this page.  Be the first to start a new thread.