if (`window -exists CurveFromNormal`) deleteUI CurveFromNormal; string $window = `window -title "Curve From Normal" -iconName "Script" -widthHeight 210 230 CurveFromNormal`; columnLayout -adjustableColumn true; setParent ..; rowColumnLayout -numberOfColumns 2; text -label "Length:"; string $Length = `floatField -v 1`; text -label "Number of spans:"; string $NSpans = `intField -v 4`; text -label "Name emited curve:"; string $name = `textField -text "n_curve"`; setParent ..; columnLayout -adjustableColumn true -rowSpacing 3; string $CheckName = `checkBox -v 0 -l "Use name from scene" -align "center" `; string $CheckNormal = `checkBox -v 1 -l "Use normal" -align "center" `; separator -height 5 -style "single"; separator -height 8 -style "none"; button -label "Create \"normal\"" -c ("CheckProc($Length,$NSpans,$name,$CheckName,$CheckNormal)"); button -label "Pick Name From Scene" -c ("pickName($name)"); button -label "Create Curve" -c ("CreateCurve($Length,$NSpans,$name)"); setParent ..; showWindow $window; proc CheckProc(string $Length, string $NSpans, string $name, string $CheckName, string $CheckNormal) { global string $nameCobj; string $nameCobj = `textField -q -text $name`; global int $CheckRead; int $CheckRead = `checkBox -q -v $CheckName`; if ($CheckRead==0) { CreateCurve($Length, $NSpans, $name); } loopCreate($name,$CheckNormal); } proc pickName(string $name) { string $newNameObjs[] = `ls -sl`; string $newName = $newNameObjs[0]; textField -e -text $newName $name; } proc CreateCurve(string $Length, string $NSpans, string $name) { string $nextSel[] = `ls -sl`; float $LengthC = `floatField -q -value $Length`; int $NSpansC = `intField -q -value $NSpans`; global string $nameCobj; string $nameCobj = `textField -q -text $name`; $NSpansC = $NSpansC - 1; float $CurvPart = $LengthC/$NSpansC; string $curveP = ""; float $i = 0; while ($i <= $LengthC) { $curveP = ($curveP+"-p 0 "+$i+" 0 "); $i = $i + $CurvPart; } $curveP = ("curve -d 3 "+$curveP+";"); eval $curveP; rename $nameCobj; select $nextSel; } proc loopCreate(string $name,string $CheckNormal) { global int $CheckReadN; int $CheckReadN = `checkBox -q -v $CheckNormal`; string $nameCobj = `textField -q -text $name`; string $SelComp[] = `ls -sl -fl`; string $forComp; for ($forComp in $SelComp) { select $forComp; XYZread($forComp,$nameCobj); } if ($CheckReadN == 1) { string $nameCobjN = ($nameCobj+"*"); select $nameCobjN; string $selCons[] = `ls -sl -as -g $nameCobjN`; select -d $selCons; doDelete; } global int $CheckRead; if ($CheckRead==0) { select $nameCobj; doDelete; } select $SelComp; } proc XYZread(string $forComp,string $nameCobj) { float $XYZ[] = `xform -q -ws -t`; int $size= `size $XYZ`; int $size_p= $size/3; int $zero = 0; string $xReZ = ""; while ($zero < $size) { string $part = ("$XYZ["+$zero+"]+"); $xReZ = ($xReZ+$part); $zero = $zero +3; if ($zero>=($size-1)) { $zero=1; string $yReZ = ""; while ($zero < $size) { $part = ("$XYZ["+$zero+"]+"); $yReZ = ($yReZ+$part); $zero = $zero +3; if ($zero>=($size-1)) { $zero=2; string $zReZ = ""; while ($zero < $size) { $part = ("$XYZ["+$zero+"]+"); $zReZ = ($zReZ+$part); $zero = $zero +3; if ($zero>=($size)) EditorText($xReZ,$yReZ,$zReZ,$size_p,$XYZ,$forComp,$nameCobj); } } } } } } proc EditorText(string $xReZ,string $yReZ,string $zReZ, int $size_p, float $XYZ[],string $forComp,string $nameCobj) { $xReZ=startString ($xReZ,`size $xReZ`-1); $xReZ=("float $XYZ[] = `xform -q -ws -t`; float $vx = ("+$xReZ+")/"+$size_p+";"); $yReZ=startString ($yReZ,`size $yReZ`-1); $yReZ=("float $XYZ[] = `xform -q -ws -t`; float $vy = ("+$yReZ+")/"+$size_p+";"); $zReZ=startString ($zReZ,`size $zReZ`-1); $zReZ=("float $XYZ[] = `xform -q -ws -t`;float $vz = ("+$zReZ+")/"+$size_p+";"); float $rx = `eval $xReZ`; float $ry = `eval $yReZ`; float $rz = `eval $zReZ`; select $nameCobj; duplicate; move -a $rx $ry $rz; string $ForConstrain[] = `ls -sl`; select $forComp; select -add $ForConstrain; global int $CheckReadN; if ($CheckReadN == 1) { geometryConstraint -weight 1; normalConstraint -weight 1 -aimVector 0 1 0 -upVector 0 1 0 -worldUpType "vector" -worldUpVector 0 1 0; } }