PDA

View Full Version : My first script : Vine Creator


joshin42
07-23-2005, 12:38 AM
Hello All!

I whipped up my first mel script last night and am having a bit of trouble with some areas.


----------------------------vinecreatorwindow.mel--------------------------------
string $winName = "vineWindow";
if(`window -ex $winName`)
{
deleteUI -window $winName;
}
window -rtf true -t "Vine Creator" $winName;
columnLayout;

//create controls
floatSliderGrp -l "Initial Size" -min .1 -max 100 -value .1 -field true insize;
intSliderGrp -l "Divisions" -min 2 -max 200 -value 10 -field true divs;
intSliderGrp -l "Sections" -min 4 -max 100 -value 8 -field true secs;
floatSliderGrp -l "Taper" -max 0.5 -pre 3 -field true taper;
floatFieldGrp -l "Twist" -nf 3 -pre 2 twist;
floatFieldGrp -l "Curl" -nf 3 -pre 2 curl;
floatFieldGrp -l "Vector Translation" -nf 3 -pre 2 vtrans;

//Radio Button Controls
radioButtonGrp -numberOfRadioButtons 3 -label "Output Geometry"
-labelArray3 "NURBS" "SubDivision" "Polygons"
-on1 "" -on2 "" -on3 ""
-sl 1
geometryRB;
button -c "getValues" -label "Create Vine";
showWindow vineWindow;

//define values for global procedure
proc getValues () {
float $size = `floatSliderGrp -q -value insize`;
int $divisions = `intSliderGrp -q -value divs`;
float $taper = `floatSliderGrp -q -value taper`;
int $rbval = `radioButtonGrp -q -sl geometryRB`;
int $sections = `intSliderGrp -q -value secs`;
float $twistx = `floatFieldGrp -q -v1 twist`;
float $twisty = `floatFieldGrp -q -v2 twist`;
float $twistz = `floatFieldGrp -q -v3 twist`;
float $vtransx = `floatFieldGrp -q -v1 vtrans`;
float $vtransy = `floatFieldGrp -q -v2 vtrans`;
float $vtransz = `floatFieldGrp -q -v3 vtrans`;
float $curlx = `floatFieldGrp -q -v1 curl`;
float $curly = `floatFieldGrp -q -v2 curl`;
float $curlz = `floatFieldGrp -q -v3 curl`;
createVine $divisions $size $taper $rbval $sections
$twistx $twisty $twistz
$vtransx $vtransy $vtransz
$curlx $curly $curlz;
}

-------------------------------vineCreate.mel--------------------------------

global proc createVine (float $numDiv, float $size, float $taper, int $rbval, int $sections,
float $twistx, float $twisty, float $twistz,
float $vtransx, float $vtransy, float $vtransz,
float $curlx, float $curly, float $curlz)
{
circle -r $size -nr 0 1 0 -s $sections -ch 1 -n circle1;
string $circles[] = `ls -sl`;

//calculate move, rotate and curl increments
float $movex = ($vtransx/$numDiv);
float $movey = ($vtransy/$numDiv);
float $movez = ($vtransz/$numDiv);
float $rotx = ($twistx/$numDiv);
float $roty = ($twistx/$numDiv);
float $rotz = ($twistx/$numDiv);
float $tape = (1 - $taper);
float $crlx = ($curlx/$numDiv);
float $crly = ($curly/$numDiv);
float $crlz = ($curlz/$numDiv);

//specify duplicates for number of divisions and execute
int $num = ($numDiv - 1);

for ($dups = 1; $dups <= $num; $dups++)
{
duplicate;
move -r $movex $movey $movez;
rotate -r $rotx $roty $rotz;
scale -r $tape $tape $tape;
rotate -r -p 0 0 0 $crlx $crly $crlz;
}}


Now, I'm having some issues trying to automate the loft procudure. I would like to store the name of each circle created throughout the looping process into a string array in order to select the circles in order to prepare for the loft. I've tried several methods and cannot seem to get a functional design! Does anyone have some advice as to how I could achieve this?

I know I have some cleanup to do and I am planning on adding some good controls still. Any help would be much appreciated! This stuff is fun! :bounce:

Cheers

DangerAhead
07-23-2005, 01:51 AM
You need to have the string variable as an array like this:



string $circleName[] = `circle -r $size -nr 0 1 0 -s $sections -ch 1 -n circle1`;

print $circleName[0]; // this will give you the name of the circle

joshin42
07-23-2005, 03:18 AM
Great thanks danger. But how can I populate the array with the names of all the circles that are created by the duplicate commands in the for loop? Running that script in the for loop will just overwrite the single entry in the array wont it?

Every time that circle is duplicated and scaled I want to append the name of the new circle into the array. Wouldn't I use `ls-sl` somewhere in that loop?

Thanks again!

Iconoklast
07-23-2005, 09:33 AM
store duplicate in an array:

string $dupName[] = `duplicate`;
// Result: pCube2 //

if you want to add the duplicated result (in thise case pCube2) into an array, but storing each name into the same array, you'll need a for loop like this:
for ($dups = 1; $dups <= $num; $dups++)
{
$dupName[$i] = `duplicate`;
scale -r $tape $tape $tape $dupName[$i];
}

joshin42
07-23-2005, 10:29 PM
Thank you Icon

However, I am having troubles executing that. Here are my changes:

//create initial circle and array to store duplicates
string $dupName[] = `circle -r $size -nr 0 1 0 -s $sections -ch 1`;

for ($dups = 1; $dups <= $num; $dups++)
{
$dupName[$dups] = `duplicate`;
move -r $movex $movey $movez;
rotate -r $rotx $roty $rotz;
scale -r $tape $tape $tape;
rotate -r -p 0 0 0 $crlx $crly $crlz;
}

//select the circles for loft operation
for ($i=0; $i<=$num; $i++)
{
select -af $dupName[$i];
}

When I run this I am getting the error:
// Error: Cannot convert data of type string[] to type string. //

What am I missing!?

Thanks a bunch... cant wait to get this working so I can add some more features.:)

Iconoklast
07-23-2005, 11:20 PM
hey sorry, I gave bad advice sorry, I know what the issue is. You're trying to cast `duplicate` into a single element of an array, which is giving you that error, what you'll need to do instead is:
string $duplicate[] = `duplicate`;
$dupName[$dups] = $duplicate[0];

also make sure with the duplicate command you're specifying what object to duplicate, ie, do
`duplicate $dupName[$dups]`;

also, you should be able to remove the need for the second loop by using the select -add instead.

joshin42
07-24-2005, 04:26 AM
Thank you so much! Got it figured out with your help =).
I wasnt able to get rid of the other for loop so I stuck with the seperate design. I got that same error when I tried to bring that in... I'll have to study closer to see exactly how that happens. Anyways, I could just duplicate that for loop to delete my orignal circles.

well its workin great now =) Time to throw in some more controls and calculations ;-)

I'll throw the mels up again when I complete the rest of the existing controls (geometry type)

Thanks a bunch!

joshin42
08-10-2005, 04:00 AM
http://img.photobucket.com/albums/v296/joshin42/renders/vineexample.gif http://img.photobucket.com/albums/v296/joshin42/renders/vineexample2.gif http://img.photobucket.com/albums/v296/joshin42/renders/vineexample3.gif



Couple examples of what it can do....

Mikademius
08-11-2005, 12:47 PM
aaand, maybe release it so we don't have to go thruogh corrections in order to get it to work if we want to try it out.
Congrats on your first script man, makes you want to change the world, doesn't it ;)

joshin42
08-12-2005, 07:16 AM
Ya.. sorry bout that! meant to post it :blush:

Sorry I don't have a website up yet so... here are the scripts.

-------------VineCreatorWindow.mel---------------

source vineCreate;

if(`window -ex $winName`)
deleteUI -window $winName;

window -rtf true -t "Vine Creator" $winName;
columnLayout;


//create controls
floatSliderGrp -l "Initial Size" -min .1 -max 100 -value 3 -field true insize;
intSliderGrp -l "Divisions" -min 2 -max 200 -value 10 -field true divs;
intSliderGrp -l "Sections" -min 4 -max 100 -value 8 -field true secs;
floatSliderGrp -l "Taper" -max 0.3 -pre 3 -field true taper;
floatFieldGrp -l "Twist" -nf 3 -pre 2 twist;
floatFieldGrp -l "Curl" -nf 3 -pre 2 -v1 0 -v2 300.00 -v3 360 curl;
floatFieldGrp -l "Vector Translation" -nf 3 -pre 2 -v1 20.00 -v2 80 -v3 0 vtrans;
//Radio Button Controls
radioButtonGrp -numberOfRadioButtons 3 -label "Output Geometry"
-labelArray3 "NURBS" "SubDivision" "Polygons"
-on1 "" -on2 "" -on3 ""
-sl 1
geometryRB;

button -c "getValues" -label "Create Vine";
showWindow vineWindow;

//define values for global procedure

proc getValues () {
float $size = `floatSliderGrp -q -value insize`;
int $divisions = `intSliderGrp -q -value divs`;
float $taper = `floatSliderGrp -q -value taper`;
int $rbval = `radioButtonGrp -q -sl geometryRB`;
int $sections = `intSliderGrp -q -value secs`;
float $twistx = `floatFieldGrp -q -v1 twist`;
float $twisty = `floatFieldGrp -q -v2 twist`;
float $twistz = `floatFieldGrp -q -v3 twist`;
float $vtransx = `floatFieldGrp -q -v1 vtrans`;
float $vtransy = `floatFieldGrp -q -v2 vtrans`;
float $vtransz = `floatFieldGrp -q -v3 vtrans`;
float $curlx = `floatFieldGrp -q -v1 curl`;
float $curly = `floatFieldGrp -q -v2 curl`;
float $curlz = `floatFieldGrp -q -v3 curl`;
createVine $divisions $size $taper $rbval $sections
$twistx $twisty $twistz
$vtransx $vtransy $vtransz
$curlx $curly $curlz;
};



--------------createVine.mel-------------

global proc createVine (float $numDiv, float $size, float $taper, int $rbval, int $sections,
float $twistx, float $twisty, float $twistz,
float $vtransx, float $vtransy, float $vtransz,
float $curlx, float $curly, float $curlz)
{
//create initial circle and array to store duplicates
string $dupName[] = `circle -r $size -nr 0 1 0 -s $sections -ch 1 -n circle1`;

//calculate move, rotate and curl increments
float $movex = ($vtransx/$numDiv);
float $movey = ($vtransy/$numDiv);
float $movez = ($vtransz/$numDiv);
float $rotx = ($twistx/$numDiv);
float $roty = ($twistx/$numDiv);
float $rotz = ($twistx/$numDiv);
float $tape = (1 - $taper);
float $crlx = ($curlx/$numDiv);
float $crly = ($curly/$numDiv);
float $crlz = ($curlz/$numDiv);
//specify duplicates for number of divisions and execute
int $num = ($numDiv - 1);
for ($dups = 0; $dups <= $num; $dups++)
{
string $duplicate[] = `duplicate`;
$dupName[$dups] = $duplicate[0];
move -r $movex $movey $movez;
rotate -r $rotx $roty $rotz;
scale -r $tape $tape $tape;
rotate -r -p 0 0 0 $crlx $crly $crlz;
}
//select the circles for loft operation
select circle1;
for ($i=0; $i<=$num; $i++)
{
select -af $dupName[$i];
}
//string $vineName = `loft -n Vine`;
string $vineName[] = `loft`;
select circle1;
for ($j=0; $j<=$num; $j++)
{
select -af $dupName[$j];
}
delete;
select $vineName[0];
switch ($rbval) {
case 1:
break;
case 2:
nurbsToSubdiv;
break;
case 3:
nurbsToPoly -pc 1000;
break;
}
}

-------------------------------------------------------------------


The polygon output still leaves the NURBS surface behind. I need to insert some conversion controls but it works alright for the time being. Hope you can have some fun with this! Any suggestions or critiques are always welcome! Oh- and yes mikademius.... very empowering!

:twisted: lol

Cheers!

joshin42
08-12-2005, 07:28 AM
I accidently didn't cut some of the window script to paste! Here is the correct script:

------------------vineCreatorWindow.mel-------------------
source vineCreate;
string $winName = "vineWindow";

if(`window -ex $winName`)
deleteUI -window $winName;
window -rtf true -t "Vine Creator" $winName;
columnLayout;


//create controls
floatSliderGrp -l "Initial Size" -min .1 -max 100 -value 3 -field true insize;
intSliderGrp -l "Divisions" -min 2 -max 200 -value 10 -field true divs;
intSliderGrp -l "Sections" -min 4 -max 100 -value 8 -field true secs;
floatSliderGrp -l "Taper" -max 0.3 -pre 3 -field true taper;
floatFieldGrp -l "Twist" -nf 3 -pre 2 twist;
floatFieldGrp -l "Curl" -nf 3 -pre 2 -v1 0 -v2 300.00 -v3 360 curl;
floatFieldGrp -l "Vector Translation" -nf 3 -pre 2 -v1 20.00 -v2 80 -v3 0 vtrans;

//Radio Button Controls
radioButtonGrp -numberOfRadioButtons 3 -label "Output Geometry"
-labelArray3 "NURBS" "SubDivision" "Polygons"
-on1 "" -on2 "" -on3 ""
-sl 1
geometryRB;

button -c "getValues" -label "Create Vine";

showWindow vineWindow;

//define values for global procedure
proc getValues () {
float $size = `floatSliderGrp -q -value insize`;
int $divisions = `intSliderGrp -q -value divs`;
float $taper = `floatSliderGrp -q -value taper`;
int $rbval = `radioButtonGrp -q -sl geometryRB`;
int $sections = `intSliderGrp -q -value secs`;
float $twistx = `floatFieldGrp -q -v1 twist`;
float $twisty = `floatFieldGrp -q -v2 twist`;
float $twistz = `floatFieldGrp -q -v3 twist`;
float $vtransx = `floatFieldGrp -q -v1 vtrans`;
float $vtransy = `floatFieldGrp -q -v2 vtrans`;
float $vtransz = `floatFieldGrp -q -v3 vtrans`;
float $curlx = `floatFieldGrp -q -v1 curl`;
float $curly = `floatFieldGrp -q -v2 curl`;
float $curlz = `floatFieldGrp -q -v3 curl`;
createVine $divisions $size $taper $rbval $sections
$twistx $twisty $twistz
$vtransx $vtransy $vtransz
$curlx $curly $curlz;
};

--------------------------------------------------------------------------

Sorry bout that! OH- and thanks for the interest Mik ^^

Take care!
:beer:

drGonzo
08-12-2005, 07:29 AM
Your UI has some syntax errors (window comand)

This is better:
if(`window -ex vineWin`)
deleteUI -window vineWin;

window -rtf true -t "Vine Creator" vineWin;
columnLayout;


//create controls
floatSliderGrp -l "Initial Size" -min .1 -max 100 -value 3 -field true insize;
intSliderGrp -l "Divisions" -min 2 -max 200 -value 10 -field true divs;
intSliderGrp -l "Sections" -min 4 -max 100 -value 8 -field true secs;
floatSliderGrp -l "Taper" -max 0.3 -pre 3 -field true taper;
floatFieldGrp -l "Twist" -nf 3 -pre 2 twist;
floatFieldGrp -l "Curl" -nf 3 -pre 2 -v1 0 -v2 300.00 -v3 360 curl;
floatFieldGrp -l "Vector Translation" -nf 3 -pre 2 -v1 20.00 -v2 80 -v3 0 vtrans;
//Radio Button Controls
radioButtonGrp -numberOfRadioButtons 3 -label "Output Geometry"
-labelArray3 "NURBS" "SubDivision" "Polygons"
-on1 "" -on2 "" -on3 ""
-sl 1
geometryRB;

button -c "getValues" -label "Create Vine";
showWindow vineWin;

joshin42
08-12-2005, 07:39 AM
Hmmm... thanks Drgonzo. OH! you pulled my original post... haha. I was posting the revised version while you were copying it. :eek: Sorry! LOL. The last vineCreatorWindow.mel script I posted is functional.

CGTalk Moderation
08-12-2005, 07:39 AM
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.