View Full Version : generative tool
fbitonti 09-27-2005, 07:07 PM Ok i'm an architecture student exploring mel scripting as a means of generating geometry. I'm working on this littel script....
for ($i = 0; $i < 20; $i = $i + 1)
{
float $curvealgo = sin($i) *$i/4;
string $name = "test" + $i;
duplicate -rr;
move -r 1 $curvealgo 0;
rename ("test" + $i);
print ($name);
if($name.translateX < 0){
move -r 1 50 0;
}
}
My ultimage goal is to have the script douplicate a specific geometry while responding to it's enviroment for example moving around a box instead of going directly through it. My problem is this... To do this I need to set up an if statement... I think (this is somewhat new to me) and use that statement to check the position of the object and if it's x,y,z value is greater than a specific value I want to execute a new series of comands. I am getting syntax errors with this script... how can I intergrate the if statement into this loop. Please respond quickly. I realy appreciate all your help.
|
|
swardson
09-27-2005, 07:22 PM
I am confused about whether or not you are writing a mel script or an expression. If you are writing a mel script, here is your problem:
if($name.translateX < 0){
move -r 1 50 0;
}
you cant directly get the value of of an objects attribute from mel, only from an expression.
to do this, you want to use the getAttr function.
string $object = ($name + ".translateX");
float $nameTX = `getAttr $object`;
if ($nameTX <0){
move -r 1 50 0;
}
if you are writing an expression that continually executes, you will want to avoid getAttr and use something else.
let me know if this helps or if I am confused
-Brad
fbitonti
09-27-2005, 07:27 PM
Ok i'm still having the problem
for ($i = 0; $i < 20; $i = $i + 1)
{
float $curvealgo = sin($i) *$i/4;
string $name = "test" + $i;
duplicate -rr;
move -r 1 $curvealgo 0;
rename ("test" + $i);
print ($name);
if($name.translateX < 0){
move -r 1 50 0;
}
}
This is what my script looks like now but i'm still getting the syntax error.
The way i'm using this is that I'm creating a nurbs object.
then i'm selecting it
then I execute this littel script.
however it does not work.
Thank you so much for the quick answere. if your still confused please let me know.
fbitonti
09-27-2005, 07:42 PM
basicaly i just want to know how to intergrate the if statement into the look and not get an error....
enbee
09-27-2005, 08:10 PM
did you try what musicraker said?
fbitonti
09-27-2005, 08:19 PM
yes i did try what he said I posted those alterations in the script on my last post. I still get the syntax error.
the error looks like this
// Error: if ($name.translateX < 0)
//
// Error: Syntax error //
enbee
09-27-2005, 08:37 PM
Well I don't see that you did in the code you posted. You are still trying to get directly at an attribute and you can't do that in a mel script. You can't say $name.translateX . You have to use the getAttr command and put the result of that into a new variable, then use that variable in the if statement.
swardson
09-27-2005, 08:49 PM
yeah, you didnt do what I suggested,
here run this code and see if it does what you want.
for ($i = 0; $i < 20; $i++){
float $curvealgo = sin($i) *$i/4;
string $name = "test" + $i;
duplicate -rr;
move -r 1 $curvealgo 0;
rename ("test" + $i);
print ($name);
string $object = ($name + ".translateX");
float $nameTX = `getAttr $object`;
if ($nameTX <0){
move -r 1 50 0;
}
}
I ran this and got no syntax errors, so hopefully there will be no logic errors in the code.
-Brad
fbitonti
09-27-2005, 09:42 PM
ok guys i was reading the post wrong. thanks a bunch!!!
CGTalk Moderation
09-27-2005, 09:42 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.