PDA

View Full Version : global float in {}?


anopheles
01-08-2006, 03:03 PM
Okay here my code:
global proc endpointer () {

string $currentselection[] = `ls -sl`;

// check to see if curve
string $shapenode[] = (`listRelatives -pa -s $currentselection`);
string $nodechecker = `nodeType $shapenode[0]`;

if ($nodechecker != "nurbsCurve")
print "Selection was not a curve, creating default curve";
curve -d 3 -p 0 0 0 -p 1 4 0 -p 1.886928 7.619122 0 -p 2.58097 10.04827 0 -p 4.229321 12.781062 0 -p 6.26807 13.691993 0 -p 7.786288 13.691993 0 -k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 4 -k 4 ;
string $currentselection[] = `ls -sl`;

else {

if ($nodechecker == "nurbsCurve")

for ($current in $currentselection)
{
string $shapenode[] = (`listRelatives -s $current`);
int $numCV = `getAttr -s ($shapenode[0]+".controlPoints")`;
float $lastsel = `select -r ($currentselection[0]+".cv["+($numCV-1)+"]")`;
float $xypos[] = `xform -ws -q -t`;
anoCurver $xypos $currentselection;

}}};

This should be a pretty simple script I know what the problem is and why it is not
working but I dont know how to fix it.

The part which is interessting for you is this one:
if ($nodechecker != "nurbsCurve")
print "Selection was not a curve, creating default curve";
curve -d 3 -p 0 0 0 -p 1 4 0 -p 1.886928 7.619122 0 -p 2.58097 10.04827 0 -p 4.229321 12.781062 0 -p 6.26807 13.691993 0 -p 7.786288 13.691993 0 -k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 4 -k 4 ;
string $currentselection[] = `ls -sl`;

else {

So if the selections shape node is not a curve it should create the default curve
and put it in the $currenselection array. The problem is is this is localy stored,
because when I want to get the currentselection a a different {} it cant get it
anymore. How can I pass the string $currentselection[] = `ls -sl`; to a
different bracket?

Thanks ;)

anopheles

sunit
01-08-2006, 03:24 PM
global proc endpointer ()
{
string $currentselection[] = `ls -sl`;
string $shapenode[];
string $nodechecker;

if (size($currentselection) > 0){
// check to see if curve
//
$shapenode = (`listRelatives -pa -s $currentselection`);
$nodechecker = `nodeType $shapenode[0]`;
}

if ($nodechecker != "nurbsCurve"){
print "Selection was not a curve, creating default curve";
curve -d 3 -p 0 0 0 -p 1 4 0 -p 1.886928 7.619122 0 -p 2.58097 10.04827 0 -p 4.229321 12.781062 0 -p 6.26807 13.691993 0 -p 7.786288 13.691993 0 -k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 4 -k 4 ;
$currentselection = `ls -sl`;
}

else if ($nodechecker == "nurbsCurve"){
for ($current in $currentselection) {
string $shapenode[] = (`listRelatives -s $current`);
int $numCV = `getAttr -s ($shapenode[0]+".controlPoints")`;
float $lastsel = `select -r ($currentselection[0]+".cv["+($numCV-1)+"]")`;
float $xypos[] = `xform -ws -q -t`;
anoCurver $xypos $currentselection;
}
}
}

endpointer;



i've changed a couple of things as well as formatted the code (this was just for my own sake to be able to read it quickly).

i've bracketed your if/then statements, but if you have just have one line following the condition (or one loop, or one other condition) then you don't need the brackets.

i'm also checking that if you don't have anything selected, your script won't return an error (which it will, if you try to get the shapeNode of nothing).

in order for your variables to work in different loops and conditions, you want to make sure to declare them at the top level. then, when you define them, you don't need to tell maya again what type of variable it is (string, float, etc) and also whether or not it's an array. otherwise, you're just re-declaring the variable within a loop/condition, and the value for that variable can only be used within the loop/condition.

cheers,
sunit

anopheles
01-08-2006, 03:58 PM
thanks a billion!

didn't think of declaring a variable outside the if statement.

thanks for putting the size command, you never know when your selecting nothing ;)

Da du in Deutschland lebst, hier nochmals danke in Deutsch:
Danke!

anopheles
01-08-2006, 05:13 PM
Since I dont want to spam the forums with new threads here a new question ;)

How can I add to arrays together, like

float $firtarray = ``xform -ws -q -t`;
float $secondarray = `xform -ws -q -t`;
float $addition = `($secondarray) + ($firstarray)`;


What I want to do is add the x y z values individually into a "addition array".

Or is here the vector data type appropriate?

vector $firtarray = ``xform -ws -q -t`;
vector $secondarray = `xform -ws -q -t`;
float $addition = `($secondarray.x) + ($firstarray.x)
($secondarray.y) + ($firstarray.y)
($secondarray.z) + ($firstarray.z)`;
?
Thanks!

sunit
01-08-2006, 06:04 PM
xform will only return float values. you can add the array like this:


float $first[3] = `xform -ws -q -t`;
float $second[3] = `xform -ws -q -t`;

float $third[3] =( {$first[0]+$second[0]), ($first[1]+$second[1]), ($first[2]+$second[2])};

viel glueck,
sunit

anopheles
01-08-2006, 06:39 PM
Ich muss dich leider korrigieren, du hast ( und { verwechselt ;)

trotzdem vielen dank :)

float $first[3] = `xform -ws -q -t`;
float $second[3] = `xform -ws -q -t`;

float $third[3] = {($first[0]+$second[0]), ($first[1]+$second[1]), ($first[2]+$second[2])};

anopheles
01-08-2006, 08:02 PM
okay,
this is the last mel specific question for this week (2hrs to go)!

Again this is curve related.
I want to connect the curve1.cv[1] xyz to a given object so something like this

connectAttr curve1.cv[1].ty cube1.ty

BUT individual CV's dont have a transform node, so there is no ...cv[1].ty

is there a workaround? I know you can query individual ones. What I want to do
is let a given object follow a cv.

Thanks!

sunit
01-08-2006, 11:04 PM
you can do this a number of ways, but i would probably use a node network.

you can create a pointOnCurveInfo node, either by selecting the curve and "pointOnCurve -ch 1", or by "createNode pointOnCurveInfo". this node will output the worldspace position (i think it's world) of the u parameter that you give it (if your curve is normalized, then it ranges from 0 - 1). you can connect this attribute to the translate of an object ("connectAttr -f pointOnCurveInfo.position object.translate").

cheers,
sunit

CGTalk Moderation
01-08-2006, 11:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.