PDA

View Full Version : Using "Global String" ?


safakoner
11-24-2003, 09:53 PM
Hi

How can I use global string ?

for example :

string $CurSel[] = `ls -sl`;
string $sproxy[] = `polyDuplicateAndConnect $CurSel[0] `;

I want to call $sproxy and $CurSel in other procedures. How can I use global string definition ?

mhovland
11-24-2003, 10:47 PM
global string $CurSel[];
global string $sproxy[];

$CurSel[] = `ls -sl`;
$sproxy[] = `polyDuplicateAndConnect $CurSel[0] `;

Declare the variables as global first, then populate them. Also remember to add the global declarations to the start of any procedure that needs to access them.


:thumbsup:

Jhavna
11-25-2003, 09:07 AM
Be careful what you name them though, as global variables will be global through ALL of Maya and all other scripts. ou just want to avoid name clashes.

0.02

safakoner
11-25-2003, 10:52 AM
Hi

Thanks.
But I have some problems.

I want to call $base in other procs. I can't do this because
I have so many string (one within the other) inside my procedures. I confused :) :( .
Do you have an scripted example ?.

Thats mine :

global proc spsbs_c()
{
//Selection Control
string $CurSel[] = `filterExpand -sm 12`;
if(`size($CurSel)` == 0)

error "No polygon object selected.\n";

else
{
if(`size($CurSel)` > 1)
error "Please select only one polygon object.\n";
else
{

//Define selection and duplicate with connection
string $CurSel[] = `ls -sl`;
string $sproxy[] = `polyDuplicateAndConnect $CurSel[0] `;
polySmooth -dv 2 -kb 0 $sproxy[0];


//Operation BaseObject
string $base = $CurSel[0];
select $base;
createDisplayLayer -name "BaseObject_L";
setAttr ($base+ ".primaryVisibility") 0;

//Rename SmoothObject
string $proxy = $proxy = ` rename $sproxy[0] ($CurSel[0] + "_Smooth")`;
select $proxy;
createDisplayLayer -name "ProxyObject_L";
layerEditorLayerButtonTypeChange ProxyObject_L;
layerEditorLayerButtonTypeChange ProxyObject_L;
}

Jhavna
11-25-2003, 11:02 AM
Basically, all you need to do, at the top of your script (outside of any procedure) declare your global string
global string $base[];
hen in the procedures you want to access the 'base' variable you have to define
global string $base[];
this tells the interpreter that when you reference the $base variable in that procedure, you are going to use the global one, not a local one.

If you fail to declare the global variable in the procedure aswell, you will create a local $base variable.

in your case:

global string $base[];

global proc spsbs_c()
{
global string $base[];

//Selection Control
string $CurSel[] = `filterExpand -sm 12`;
.
.
.
//Operation BaseObject
string $base = $CurSel[0];
select $base;
createDisplayLayer -name "BaseObject_L";
.
.
.


Does that help?

safakoner
11-25-2003, 12:03 PM
Yes, thanks again. It works.

but

I define an object called $base. When I call the $base in other proc. that don't work.
My code is below, part 2 is not working. (delete proc). That is problem.
can you help me again ?


//////////////////////////////////


if (`window -q -exists nw_w`) deleteUI nw_w;
window -title "Equinox | SP SBS" -iconName "Equinox | SP SBS" -widthHeight 105 237 nw_w;
//------------------------------------------------------------------------------------



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

//-- GUI
columnLayout;
frameLayout -label " S" -cll true -w 104;
rowLayout -numberOfColumns 2 -columnWidth 1 50 -columnWidth 2 50;
symbolButton -w 50 -h 30 -image "deneme.bmp" -c "spsbs_c" b_spsbs_c;
symbolButton -w 50 -h 30 -image "deneme.bmp" -c "spsbs_d" b_spsbs_d;
setParent..;
setParent..;


showWindow nw_w;

//------------------------------------------------------------------------------------
global string $base[];

//-- create
global proc spsbs_c()
{
global string $base[];
//Selection Control
string $CurSel[] = `filterExpand -sm 12`;
if(`size($CurSel)` == 0)
error "No polygon object selected.\n";

else
{
//Define selection and duplicate with connection
string $CurSel[] = `ls -sl`;
string $base[] = `polyDuplicateAndConnect $CurSel[0] `;
polySmooth -dv 2 -kb 0 $base[0];
}
}


//-- delete
global proc spsbs_d()
{
global string $base[];
delete $base; //-- DELETE $base
}

Jhavna
11-25-2003, 01:19 PM
i've just tried this with a little test script.
It seems to work fine for me.. What error are you getting?
I used

global string $base[];
global proc test1 ()
{
global string $base[];
$base = `ls`;
}

global proc test2 ()
{
global string $base[];
delete $base;
}

test1;
test2;

and the only error I got was that the nodes (empty scene) cannot be deleted.
Which should mean that the script syntax is correct...

safakoner
11-29-2003, 09:27 AM
its working. :bounce: But I can't use this code for my script.

Thanks for help

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