// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // Description : // A script to return the Knot sequence of a NURBS Curve // as an array of floats. It works on a curve of the // select list. // proc float[] getNurbsCurveKnots( string $crvName ) // // Description : // { float $knots[] ; string $infoNode ; // create info Node. if( catch( $infoNode = `createNode curveInfo` ) ) { return $knots ; } // connect curve on to the info node. // string $outAttr = $crvName + ".local" ; string $inAttr = $infoNode + ".ic" ; connectAttr $outAttr $inAttr ; // read the knots. // $outAttr = $infoNode + ".knots" ; $knots = `getAttr $outAttr` ; // delete curve info node. // delete $infoNode ; // return the knots. // return $knots; } global proc float[] nurbsCurveKnots() // // Description : // To get the knot sequence of the nurbs curve as // an array of floats. // NOTE : works on a NURBS curve of the selection list. // { float $knotSeq[] ; // 0. Grab the select list. // string $selList[] ; $selList = `ls -sl` ; // 1. Run filter to select only the NURBS curves. // global int $gSelectNurbsCurvesBit ; global int $gSelectCurvesOnSurfacesBit; string $crvList[] ; $crvList = `filterExpand -ex true -sm $gSelectNurbsCurvesBit $selList` ; if( size($crvList) == 0 ) { string $cosList[] ; $cosList = `filterExpand -ex true -sm $gSelectCurvesOnSurfacesBit $selList` ; if( size($cosList) == 0 ) { warning (uiRes("m_nurbsCurveKnots.kWarningNoCurveSelected")) ; return $knotSeq; } else $crvList = $cosList; } // 2. Work on the last item if more than one NURBS curve in list. // int $len = size($crvList) ; string $lastCrv = $crvList[$len-1] ; if( $len != 1 ) { string $w = `format -s $lastCrv (uiRes("m_nurbsCurveKnots.kWarningTooManyCurves"))` ; warning $w ; } // 3. Extract the Knots. // $knotSeq = getNurbsCurveKnots( $lastCrv ) ; // 4. select curve for which knots are returned. // select -r $lastCrv ; // 5. return the knots. // return $knotSeq ; }