PDA

View Full Version : ScripJob problem


Zodrac
10-10-2005, 08:54 PM
Ok my objective is to create a window with different tabs. I want different tabs to show depending on which type of light that is selected.
Since i haven't found a way to hide single tabs i have to recreate the window each time i select a new light. My problem is with the scriptjob line that is at the bottom of the 5 mile long code. The code works fine except that the scriptjobs doesn't just run when the selection is changed it keeps on running and running and i don't know why.

Any help would be appriciated.

//Zodrac

//beginglobal procHelp==============================================================================
// PROCEDURE: LightWindow_UI (global)
// ARGUEMENTS: NONE
// RETURN: NONE
// DESCRIPTION: Main procedure. Creates the light board window
//endglobal procHelp================================================================================

global proc LightWindow_UI()
{
//-=Check if window already exists and delete if it does=-
//**************************************************************************************************
if (`window -exists LightWindow`)
deleteUI -window LightWindow;
//**************************************************************************************************

//-=Creating window=-
//**************************************************************************************************
window -title "Light_Board" LightWindow;
//**************************************************************************************************

Tab_UI;
}

//beginglobal procHelp==============================================================================
// PROCEDURE: Tab_UI (global)
// ARGUEMENTS: NONE
// RETURN: NONE
// DESCRIPTION: Creates the tabs depending on whitch type of lights are selected
//endglobal procHelp================================================================================

global proc Tab_UI()
{
//-=Creating formlayout to hold all controls in the window=-
//**************************************************************************************************
string $formLight = `formLayout -numberOfDivisions 100`;
//**************************************************************************************************

//-=Creats a tablayout=-
//**************************************************************************************************
string $tabs = `tabLayout -innerMarginWidth 5 -innerMarginHeight 5`;
//**************************************************************************************************

//-=Places the tab layout=-
//**************************************************************************************************
formLayout -edit
-attachForm $tabs "top" 0
-attachForm $tabs "left" 0
-attachForm $tabs "bottom" 0
-attachForm $tabs "right" 0
$formLight;

//**************************************************************************************************

//-=If anything is selected pickwalk down to select it's shape node=-
//**************************************************************************************************
string $nodeList[] = `ls -selection`;

if (size($nodeList)>0)
{
pickWalk -d down;
}
//**************************************************************************************************

//-=Saving all selected node types into $nodeType=-
//**************************************************************************************************
string $nodeList[] = `ls -selection`;
string $nodeType[];

for($i = 0; $i < size($nodeList); $i++)
{
$nodeType[$i] = `nodeType $nodeList[$i]`;

}
//**************************************************************************************************

//-=Filtering out just the light node types and saving them to $lightList=-
//**************************************************************************************************
string $lightList[];
int $i2 = 0;

for($i = 0; $i < size($nodeType); $i++)
{
if ($nodeType[$i] == "ambientLight" || $nodeType[$i] == "directionalLight" || $nodeType[$i] == "pointLight" ||
$nodeType[$i] == "spotLight" || $nodeType[$i] == "areaLight" || $nodeType[$i] == "volumeLight")
{
$lightList[$i2] = $nodeType[$i];

$i2 ++;

}
}
//**************************************************************************************************

//-=Checks which type of lights are selected=-
//**************************************************************************************************
int $generalExist = 0;
int $ambientExist = 0;
int $directionalExist = 0;
int $pointExist = 0;
int $spotExist = 0;
int $areaExist = 0;
int $volumeExist = 0;
int $lightExist[];

for($i = 0; $i < size($lightList); $i++)
{
switch ($lightList[$i])
{
case "ambientLight":
$ambientExist = 1;
break;

case "directionalLight":
$directionalExist = 1;
break;
case "pointLight":
$pointExist = 1;
break;

case "spotLight":
$spotExist = 1;
break;

case "areaLight":
$areaExist = 1;
break;

case "volumeLight":
$volumeExist = 1;
break;
}
}

if ($ambientExist + $directionalExist + $pointExist + $spotExist + $areaExist + $volumeExist > 1)
$generalExist = 1;

$lightExist[0] = $generalExist;
$lightExist[1] = $ambientExist;
$lightExist[2] = $directionalExist;
$lightExist[3] = $pointExist;
$lightExist[4] = $spotExist;
$lightExist[5] = $areaExist;
$lightExist[6] = $volumeExist;
//**************************************************************************************************

//-=Creates all tabs depending on which types of lights are selected=-
//**************************************************************************************************
if ($lightExist[0] == 1)
{
string $generalTab = `rowColumnLayout -numberOfColumns 2`;
setParent ..;
tabLayout -edit
-tabLabel $generalTab "General"
$tabs;
}

if ($lightExist[1] == 1)
{
string $ambientTab = `rowColumnLayout -numberOfColumns 2`;
setParent ..;
tabLayout -edit
-tabLabel $ambientTab "Ambient"
$tabs;
}

if ($lightExist[2] == 1)
{
string $directionalTab = `rowColumnLayout -numberOfColumns 2`;
setParent ..;
tabLayout -edit
-tabLabel $directionalTab "Directional"
$tabs;
}

if ($lightExist[3] == 1)
{
string $pointTab = `rowColumnLayout -numberOfColumns 2`;
setParent ..;
tabLayout -edit
-tabLabel $pointTab "Point"
$tabs;
}

if ($lightExist[4] == 1)
{
string $spotTab = `rowColumnLayout -numberOfColumns 2`;
setParent ..;
tabLayout -edit
-tabLabel $spotTab "Spot"
$tabs;
}

if ($lightExist[5] == 1)
{
string $areaTab = `rowColumnLayout -numberOfColumns 2`;
setParent ..;
tabLayout -edit
-tabLabel $areaTab "Area"
$tabs;
}

if ($lightExist[6] == 1)
{
string $volumeTab = `rowColumnLayout -numberOfColumns 2`;
setParent ..;
tabLayout -edit
-tabLabel $volumeTab "Volume"
$tabs;
}
//**************************************************************************************************
showWindow($lightList);
}

//beginglobal procHelp==============================================================================
// PROCEDURE: ShowWindow (global)
// ARGUEMENTS: NONE
// RETURN: NONE
// DESCRIPTION: Shows the window if any lights are selected
//endglobal procHelp================================================================================

global proc showWindow(string $lightList[])
{
//-=Specifies the window format and shows it=-
//**************************************************************************************************
window -edit -topLeftCorner 131 3 -sizeable false -width 350 -height 425 -retain LightWindow;
showWindow;
//**************************************************************************************************
}

global proc UpdateWindow()
{
if (`window -exists LightWindow`)
LightWindow_UI;
}

LightWindow_UI;

int $selectionJob = `scriptJob -event "SelectionChanged" UpdateWindow`;

twidup
10-11-2005, 05:33 PM
I am doing something very similiar to this in a script. Since I am at work right now, I cant post an example, but I will asap.

-todd

mhovland
10-11-2005, 06:27 PM
I modified the UpdateWindow proc to the code below, and it seems to be working fine. Let me know if this works for you.

All I did was change the proc so that if the window exists, delete it, and then call the LightWindow_UI proc, else(the window doesn't exist) just call LightWindow_UI.


global proc UpdateWindow()
{
if (`window -exists LightWindow`)
{
deleteUI -window LightWindow;
LightWindow_UI;
}
else
{
LightWindow_UI;
}
}

john_homer
10-11-2005, 06:57 PM
since you run LightWindow_UI in both cases... it would be the same to just write..


global proc UpdateWindow()
{
if (`window -exists LightWindow`)
deleteUI -window LightWindow;
LightWindow_UI;
}

Zodrac
10-11-2005, 08:46 PM
Thanks for all replys. What i am trying to do with the jobscript is to update the window if a new light is selected but only if the window already is opened that's why the UpdateWindow is looking like it does.

Just to make it a little clearer just what i'm trying to accomplish with this script i'll try to explain it better. When i run the script i want an empty window to apear(If a light is selected when the script is run the window should open up with the correct tabs right away). Then when i select one or more lights a tab is created in the window for each type of light that is selected. If i then add or replace the selection with different lights the window should update with the correct tabs. If everything is deselect the window should just stay opened but empty.

I've modified the code a little bit. So here is the last few lines as it looks right now.
It doesn't work the first time the script is run (I think it's due to the -runOnce flag, but for some reson it works fine the second time). The problem is that it doesn't open an empty window if no lights are selected and the window closes if everything is deselected.

B.t.w if any one knows an easier way to accomplish all this it would really be appriciated.
Like for example if there is a way to hide just a single tab.

global proc showWindow()
{
//-=Specifies the window format and shows it=-
//**************************************************************************************************
window -edit -topLeftCorner 1 555 -sizeable false -width 350 -height 425 -retain LightWindow;
showWindow;
//**************************************************************************************************
int $selectionJob = `scriptJob -runOnce true -event "SelectionChanged" UpdateWindow`;
}

global proc UpdateWindow()
{
if(`window -exists LightWindow`)
LightWindow_UI;
}

LightWindow_UI;

//Zodrac

twidup
10-11-2005, 08:50 PM
a couple things I noticed in your original post.

the scriptjob keeps running because its not tied to anything. if you set ites parent to the window, whenever the window is killed, it will get killed as well.

You should put the scriptjob inside the proc for the window as well, that way when teh window is recalled it recreates teh script job, and of course, when teh window is destroyed, it kills the script job as well.

now, if you didnt want to delete the Window, there are other ways.

Like having the contents of the tabs as other procedures. Then teh selection is changed, the script job would kill the content of that tab and run the correct proecdure to create the new UI components.

-todd

CGTalk Moderation
10-11-2005, 08:50 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.