PDA

View Full Version : returning the names of smoothNodes


Scott212
12-27-2003, 04:19 AM
In the script I'm writing there is a polySmooth node created and I was wondering if there was a way to catch the name of the node as it's created so I can control it later.


if ($type == "transform") {
polySmooth -mth 0 -dv 2 -c 1 -kb 0 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1 $obj;
select -cl;
}

Scott212
12-27-2003, 06:14 AM
why doesn't the -name flag on the create polySmooth node seem to do anything?

sbp
12-27-2003, 10:13 AM
hi,
I don't know why -n doesn't work but,
string $nnn[] = `polySmooth....`;
should catch the name of the new node(s).

Scott212
12-27-2003, 01:55 PM
Hey thanks for your reply! I'm almost there but I'm not sure why it's not quite working. Maybe anyone out there could just take a quick look and eyeball what going wrong here. Here's the section of code that I'm having a fit with:


string $obj[] = `ls -sl`;
string $winName = "smoothUndo";

if ($obj[0] != "") {
string $type = `objectType $obj`;
if ($type == "transform") {
string $smoothNode[] = `polySmooth -mth 0 -dv 2 -c 1 -kb 0 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1`;
select -cl;

//create the undo window
if ( `window -exists $winName `) {
deleteUI $winName;
}
window -menuBar true -t "" $winName;
columnLayout -adjustableColumn true;
iconTextButton -style "textOnly"
-label "Undo Smooth"
-c ("print $smoothNode[0]; deleteUI $winName;");
showWindow;
print $obj" was smoothed twice over.";
} else {
error "Current selection doesn't match required selection type. Polygonal objects required.";
}
} else {
error "You must first select the geometry to smooth.";
};

The issue is that when the button is called the $smoothNode string comes back as undeclared or empty but if I put a print statement right after the smooth command it prints it fine. It's like I'm losing the variable somehow. Any Ideas?? Thanks All!

Scott

sbp
12-27-2003, 10:30 PM
Hi,

Check the mel user guide 'variables and constants->variables' section for an understanding of global and local variables. In this case you need to use a global variable because by the time the button is actually pushed, $smoothNode[] no longer exists.

Scott212
12-28-2003, 01:32 AM
I will do this for sure and I thank you, but at what point or why does the $smoothNode die? Also when it's turned to a global string it alerts me that a global string must be a constant. If I'm dynamically aquiring this string then it will never be a constant, correct?

sbp
12-28-2003, 03:46 AM
Hi,

It's lifetime or 'scope' is local to the block it's declared in.

string $winName=...; // this is outside any blocks which is global

if ($type == "transform") {

string $smoothNode[] = ...; // this is local which is only valid for the encasing {} brackets

}

// $winName is still good
// $smoothNode[] is no longer valid.

The code assigned to the button is only defined within your script. When the button is pressed, the code is executed in the context of a seperate script containing only this,

{
print $smoothNode[0];
deleteUI $winName;
}

If you change your script to

string $smoothNode[];
string $winName = ...;
string $obj=...;
{
$smoothNode = `polySmooth...`;
}

you should be ok as far as your variables are concerned, and hopefully this makes more sense.

Scott212
12-28-2003, 02:15 PM
Thanks for all of your help sbp, I got it finished and working. It's a simple polySmooth checker if you don't want to use a proxy or subd.

Feel free to put it on your shelf :beer:


// Simple PolySmooth Checker v1.0
// ANY questions or comments send to wokontheotion@hotmail.com
// Scott Willman 2003

string $obj[] = `ls -sl`;
string $smoothNode[];
string $winName = "smoothUndo";
string $smoothCommand = ($smoothNode[0] + ".divisions");
print $smoothNode[0];

if ($obj[0] != "") {
string $type = `objectType $obj`;
if ($type == "transform") {
//create the undo window
if ( `window -exists $winName `) {
deleteUI $winName;
}
window -t "" $winName;
columnLayout -adjustableColumn true;
$smoothNode = `polySmooth -mth 0 -dv 2 -c 1 -kb 0 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1`;
print $smoothNode[0];
select -cl;

iconTextButton -style "textOnly"
-label "Undo Smooth"
-c ("print $smoothNode[0]; setAttr ($smoothNode[0] + \".divisions\") 0; deleteUI $winName; select $obj[0];");
showWindow;
print $obj" was smoothed twice over.";
} else {
error "Current selection doesn't match required selection type. Polygonal objects required.";
}
} else {
error "You must first select the geometry to smooth.";
};

CGTalk Moderation
01-17-2006, 12:00 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.