PDA

View Full Version : developing a scriptedPanelType


Buexe
07-07-2008, 09:41 PM
Since I`m just a simple soul who makes errors while writing MEL scripts, I have a BBIIGGG problem developing my awesome scriptePanelType as I have to restart Maya everytime in order to check my miserable attempts to create a decent addCallback. Now, is there a way to kill my scriptedPanelType by any chance ? I have found this removePanelType command but have not figured out how to use it. Please help me save some lifetime :cry:
Thanks!

goleafsgo
07-08-2008, 03:21 AM
Do you really need to delete the type or can you do what you need by either editing the callback code itself or editing the type to have a new callback?

Buexe
07-08-2008, 08:33 AM
From my understanding it should be enough to delete the current instance of the panel, so that it builds a new one, when I call it from the panel menu, right ? But I don`t know either how to get this to work and my problem now is that all the controls and layouts are added in the addCallback procedure and so far I can get it to run only the first time I call the panel. I have tried working with scriptedPanels in the past, but this issue always got me frustrated and so I stayed away from them. Now I thought I`d ask if anybody has an idea how to get this addCallback to reinitialize the panel and/or getting rid of the scriptedPanelType so I can start from scratch and see my changes in the layout. Another thing is that in the addCallback I try to save certain controls in global variables so I can check their values later. But somehow when the addCallback is finished, those global variables are empty : ( I print them out during the addCallback and there they have the proper string to the control. I`m confused, please help!

THanks!

goleafsgo
07-08-2008, 11:05 AM
Well if you want to delete the scripted panel (not the scripted panel type) you should be able to use deleteUI.

Could you post part of the script?

Buexe
07-08-2008, 03:01 PM
THanks for your interest goleafsgo. Here is part of the code. I was able to resolve the global variable problem. Regarding the reinitialization of my panel(type) I`m still having issues. I`m able to kill my scriptedPanel, but when I recreate one Maya complains

// Error: line 1: Too many children in layout: scriptEditorPanel1

What am I doing wrong? I`m running out of ideas. Another thing I realized is that I have to run "deleteUI map" twice to really get rid of the scriptedPanel and have the removeCallback activated. Something is not running well yet, hopefully some helpful soul can help me! Thanks!

// this initializes the panel type and an instance
global proc mapPanelInit ()

{

if (!`scriptedPanelType -exists mapPanelType`)

{

scriptedPanelType -ccb mapCreateCallback

-icb mapInitCallback

-acb mapAddCallback

-rcb mapRemoveCallback

-dcb mapDeleteCallback

-scb mapSaveStateCallback

-unique true

mapPanelType;

}

if (!`scriptedPanel -exists map`)

{

scriptedPanel -type mapPanelType -label "mapLabel" map;

}

}



global proc mapCreateCallback(string $panelName)

{

print "mapCreateCallback\n";

}

global proc mapInitCallback(string $panelName)

{

print "mapInitCallback\n";

}

global proc mapRemoveCallback(string $panelName)

{

print "mapRemoveCallback\n";

}

global proc mapDeleteCallback(string $panelName)

{

print "mapDeleteCallback\n";

}

global proc mapSaveStateCallback(string $panelName)

{

print "mapSaveStateCallback\n";

}

global proc mapAddCallback(string $panelName)

{

menu -label "map" -to 1;

menuItem -label "Maya rules" ;



string $tab = `tabLayout`;



string $form1 = `formLayout`;

string $b1 = `button -l "refresh me2!" -c "mapPanelOLPoseUpdateObjectList1"`;

string $b2 = `button -l "kill me!" -c "deleteUI map;"`;

string $pane1 = `paneLayout -ps 1 50 50 -configuration "horizontal2"`;



string $editor1 = `outlinerEditor -dip 0 -ams 1 -ssm 0 `;



global string $mapPanelPoseEditorControls[];

$mapPanelPoseEditorControls[0] = `scrollLayout -cr 1 -p $pane1`;

$mapPanelPoseEditorControls[1] = `formLayout`;



formLayout -e

-attachForm $b1 "top" 0

-attachForm $b1 "left" 0

-attachControl $b2 "left" 0 $b1

-attachControl $pane1 "top" 0 $b1

-attachForm $pane1 "left" 0

-attachForm $pane1 "right" 0

-attachForm $pane1 "bottom" 0

$form1;



global string $mapOLPoseInputList1;

$mapOLPoseInputList1 = `selectionConnection -connectionList`;

global string $mapOLPoseFromEditor1;

$mapOLPoseFromEditor1 = `selectionConnection `;



editor -edit -mainListConnection $mapOLPoseInputList1 $editor1;

editor -edit -selectionConnection $mapOLPoseFromEditor1 $editor1;



selectionConnection -e -addScript mapPanelUpdatePoseList $mapOLPoseFromEditor1;

selectionConnection -e -removeScript mapPanelUpdatePoseList $mapOLPoseFromEditor1;



mapPanelOLPoseUpdateObjectList1;

}

global proc mapPanelOLPoseUpdateObjectList1 ()

{

print "this updates the outliner\n";

global string $mapOLPoseInputList1;

string $test4= `selectionConnection -e -clear $mapOLPoseInputList1`;



string $objs[] = `ls -typ camera`;

string $p[];

for ($obj in $objs)

{

clear $p;

$p = `listRelatives -p -pa $obj`;

selectionConnection -e -s $p $mapOLPoseInputList1;

}

}



global proc mapPanelUpdatePoseList( string $objs[] )

{

print "mapPanelUpdatePoseList\n";

global string $mapPanelPoseEditorControls[];



$width = `scrollLayout -q -w $mapPanelPoseEditorControls[0]`;

$height = `scrollLayout -q -sah $mapPanelPoseEditorControls[0]`;

deleteUI $mapPanelPoseEditorControls[1];

$mapPanelPoseEditorControls[1] = `formLayout -w ($width-32) -p $mapPanelPoseEditorControls[0]`;

button -l $objs[0];

}

NaughtyNathan
07-08-2008, 04:19 PM
I'm not an expert on ScriptedPanels but I've created one in the past that seems to perform without issues... It was a while ago now but I seem to remember the key is to do with parenting/unparenting them rather than deleteUIing them which I don't think you should do... as an example, if you deleteUI on the UV Texture Editor Panel your entire Maya session is screwed and you'll have to restart Maya.

here is a bit of my code which may help you:


global proc sp_updatePanelUI()
{
// do the commands here to refresh/update any of your panel controls...
}
global proc sp_addCallback(string $panelName)
{
print "// AddCallback executed! - building Panel Window //\n";
columnLayout;
button;
button;
floatSliderGrp;
button;
}
global proc sp_initCallback(string $panelName)
{
print "// InitCallback executed! //\n";
if (`scriptedPanel -q -ex $panelName`)
sp_updatePanelUI;
}
global proc sp_deleteCallback(string $panelName)
{
print "// DeleteCallback executed! //\n";
scriptedPanel -unParent -type myPanel -l "My Scripted Panel!";
}
global proc initSpPanel()
{
if (!`scriptedPanelType -q -ex myPanel`)
{
scriptedPanelType
-icb sp_initCallback // used to update Panel on File-New or File-Open
-acb sp_addCallback // used to create the panel and its controls
-dcb sp_deleteCallback // used to re-authorize panel on File-New or Open
-unique 1
myPanel;
}
if (!`scriptedPanel -exists myPanel1`)
scriptedPanel -unParent -type "myPanel" -l "My Scripted Panel!";
}


run initSpPanel; to initialise it first time, then each time I want to change the ui controls in the panel, I edit the code, source it, then close the panel window (make sure it's a floating window and not an embedded panel) and use:

tearOffPanel "My Scripted Panel!" "myPanel" 1;

I can't guarentee this is the "correct" way to handle scripted panels, but Like I said, it all seems to work fine for me..
hopefully this may be of some help...

:nathaN

Buexe
07-08-2008, 06:13 PM
Hey NaughtyNathan, thanks for your infos, putting that stuff into a window helped me to get onto the right track. I think I found a reliable solution now and the solution is called :

RTFM :D

After using the hint Nathan suggested I realized I always have to at least do deleteUI twice, sometimes even 3 times to kill the panel completly. Then I thought, okay why not check the docs and there is a flag for the deleteUI command called "-panel", and testing it so far gives me good results I only have to run the deleteUI command only once, like
deleteUI -panel "mapPanel"

and now I can make an init proc to have something like
if ( `scripetPanel -exists "mapPanel" `)
deleteUI -panel mapPanel;

and that kills the old stuff and starts fresh, works with torn off and embedded panels.
Me happee now! :wavey:
Thanks everybody!

CGTalk Moderation
07-08-2008, 06:13 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.