Script to generate curve from selected objects

johnkeates2865
Advocate

Script to generate curve from selected objects

johnkeates2865
Advocate
Advocate

I'm trying to make a MEL script which will generate a curve from selected objects but I'm not having much luck. I get an error saying "Invalid flag" followed by the information I am trying to put into the curve. Also, the variable that has the information keeps including blank data but I'm not sure why.

 Please excuse my odd programming methods as I am an artist really 🙂

 

Here is my script:

//-----------------------------------------------------------------

proc makeNurbsCurveFromSelection()
{
// select -hi;
string $selection[] = `ls -sl`;
string $positions[] ;
spaceLocator -n tempLocator;
int $selectionSize = (size($selection));
matrix $itemPos[100] [3] ;
for ($i = 0 ; $i<$selectionSize ; $i++)
{
pointConstraint -n "tempConstraint" $selection[$i] tempLocator;
$itemPos [$i] [0]= `getAttr "tempLocator.translateX"`;
$itemPos [$i] [1]= `getAttr "tempLocator.translateY"`;
$itemPos [$i] [2]= `getAttr "tempLocator.translateZ"`;
delete "tempConstraint";
}

string $crvData[];

for ($i=0 ; $i<(($selectionSize)*4) ; $i++ )
{
$crvData[$i*4] = "-p";
$crvData[($i*4)+1] = (($itemPos [$i] [0]));
$crvData[($i*4)+2] = (($itemPos [$i] [1]));
$crvData[($i*4)+3] = (($itemPos [$i] [2]));
}

string $curveDataString = stringArrayToString($crvData," ");

curve -d 3 $curveDataString;
delete tempLocator;
}

//-----------------------------------------------------------------

0 Likes
Reply
Accepted solutions (1)
1,592 Views
4 Replies
Replies (4)

tony.su
Autodesk Support
Autodesk Support

I didn't read your script. For this error you can use "eval curve -d 3 $curveDataString;"

Because $curveDataString is not only one flag, so add eval.



Tony Su
Product Support

rajasekaransurjen
Collaborator
Collaborator
Accepted solution

Hi,

Try This.....

proc rsmakeNurbsCurveFromSelection()
{
    string $selection[] = `ls -sl`;
    float $positions1[] ;
    string $curvePpints[], $array[];
    for($i=0;$i<size($selection);$i++)
    {
        $positions1 = `xform -q -ws -rp $selection[$i]`;
        $curvePpints[($i*4)] = "-p";
        $curvePpints[($i*4)+1] = $positions1[0];
        $curvePpints[($i*4)+2] = $positions1[1];
        $curvePpints[($i*4)+3] = $positions1[2];
    }

    string $curveDataString = stringArrayToString($curvePpints," ");
    eval curve -d 3 $curveDataString;
}
0 Likes

johnkeates2865
Advocate
Advocate

Excellent! Thanks! That works well and your code is a hell of a lot more tidy and efficient than mine! I will study it closely.

rajasekaransurjen
Collaborator
Collaborator

you’re welcome.

0 Likes