(MEL)getting curve cv parameter?

(MEL)getting curve cv parameter?

absoluteKelvin
Collaborator Collaborator
2,070 Views
4 Replies
Message 1 of 5

(MEL)getting curve cv parameter?

absoluteKelvin
Collaborator
Collaborator

 

{
 string $selected[] = `ls -sl`;
 string $shapes[];
 float $uParam[] ;
 for ($curve in $selected){
    int $CVs =`getAttr ($curve + ".spans")`;
    $shapes = `listRelatives -shapes $curve`;
    string $nearestInfo = `createNode nearestPointOnCurve`;
    connectAttr ($shapes[size($shapes)] + ".worldSpace") ($nearestInfo +".inputCurve");
    for ($x = 0; $x < $CVs; $x++)
    {
        vector $location = `pointPosition ($curve + ".cv[" + $x + "]")`;
        setAttr ($nearestInfo + ".inPositionX") ($location.x);
        setAttr ($nearestInfo + ".inPositionY") ($location.y) ;
        setAttr ($nearestInfo + ".inPositionZ") ($location.z) ;
        $uParam[$x] = `getAttr ($nearestInfo + ".parameter")`;  //format getAttr nearestPointOnCurve1.parameter;
        string $Parameter = $uParam[$x];
        print ($Parameter + "\n");
    }
    delete $nearestInfo;
 }    
} 

 

this is the code i came up with after reading up on documentations and help from sites https://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/mel/DATA_ncurve.html

http://download.autodesk.com/global/docs/maya2012/en_us/Nodes/nearestPointOnCurve.html

 

Currently it works on one curve. But Its suppose to work for multiple curves.  When I run it it gives me

 

// Error: line 9: The source attribute '.worldSpace' cannot be found. //

 

 

 

https://www.artstation.com/kelvintam
0 Likes
Accepted solutions (1)
2,071 Views
4 Replies
Replies (4)
Message 2 of 5

stuzzz
Collaborator
Collaborator

stuzzz_0-1589053642312.png

looking at Nurbs shape output attributes in maya2018, worldSpace attribute is an array. 

so you may explicitly specify an index to worldspace ( ie. worldspace[0] )

connectAttr ($shapes[size($shapes)] + ".worldSpace[0]") ($nearestInfo +".inputCurve");

 

 

Message 3 of 5

absoluteKelvin
Collaborator
Collaborator

i edited the code with your suggestion, but this occurs when i have 2 curves selected.

 

// Error: line 9: The source attribute '.worldSpace[0]' cannot be found. //

https://www.artstation.com/kelvintam
0 Likes
Message 4 of 5

absoluteKelvin
Collaborator
Collaborator
Accepted solution

i found the issue. d'ohhh its the shapes[size($shapes)] thats causing issues

 

with this it will work regardless even without .worldSpace[0]

connectAttr -force ($shapes[0] + ".worldSpace") ($nearestInfo +".inputCurve");

 

https://www.artstation.com/kelvintam
Message 5 of 5

stuzzz
Collaborator
Collaborator

great!

0 Likes