Go to: Synopsis. Return value. Flags. MEL examples.
scriptedPanel [-control] [-copy string] [-defineTemplate string] [-docTag string] [-exists] [-init] [-isUnique] [-label string] [-menuBarVisible boolean] [-needsInit] [-parent string] [-popupMenuProcedure script] [-replacePanel string] [-tearOff] [-tearOffCopy string] [-type string] [-unParent] [-useTemplate string]
[panelName]
scriptedPanel is undoable, queryable, and editable.
This command will create an instance of the specified
scriptedPanelType. A panel is a collection of UI objects (buttons,
fields, graphical views) that are grouped together. A panel can be
moved around as a group within the application interface, and torn off
to exist in its own window. The panel takes care of maintaining the
state of its UI when it is relocated, or recreated. A scripted panel
is a panel that is defined in MEL, with all of the required callbacks
available as MEL proc's.
string | The name of the scripted panel. |
In query mode, return type is based on queried flag.
control, copy, defineTemplate, docTag, exists, init, isUnique, label, menuBarVisible, needsInit, parent, popupMenuProcedure, replacePanel, tearOff, tearOffCopy, type, unParent, useTemplate
Long name (short name) |
Argument types |
Properties |
|
-control(-ctl)
|
|
|
|
Returns the top level control for this panel.
Usually used for getting a parent to attach popup menus.
CAUTION: panels may not have controls at times. This
flag can return "" if no control is present.
|
|
-copy(-cp)
|
string
|
|
|
Makes this panel a copy of the specified panel. Both
panels must be of the same type.
|
|
-defineTemplate(-dt)
|
string
|
|
|
Puts the command in a mode where any other flags and args are
parsed and added to the command template specified in the argument.
They will be used as default arguments in any subsequent
invocations of the command when templateName is set as the
current template.
|
|
-docTag(-dtg)
|
string
|
|
|
Attaches a tag to the Maya panel.
|
|
-exists(-ex)
|
|
|
|
Returns whether the
specified object exists or not. Other flags are ignored.
|
|
-init(-in)
|
|
|
|
Initializes the panel's default state. This is usually done
automatically on file -new and file -open.
|
|
-isUnique(-iu)
|
|
|
|
Returns true if only one instance of this panel type is allowed.
|
|
-label(-l)
|
string
|
|
|
Specifies the user readable label for the panel.
|
|
-menuBarVisible(-mbv)
|
boolean
|
|
|
Controls whether the menu bar for the panel is displayed.
|
|
-needsInit(-ni)
|
|
|
|
(Internal) On Edit will mark the panel as requiring initialization.
Query will return whether the panel is marked for initialization. Used
during file -new and file -open.
|
|
-parent(-p)
|
string
|
|
|
Specifies the parent layout for this panel.
|
|
-popupMenuProcedure(-pmp)
|
script
|
|
|
Specifies the procedure called for building the panel's popup menu(s).
The default value is "buildPanelPopupMenu". The procedure should take
one string argument which is the panel's name.
|
|
-replacePanel(-rp)
|
string
|
|
|
Will replace the specified panel with this panel. If the
target panel is within the same layout it will perform a swap.
|
|
-tearOff(-to)
|
|
|
|
Will tear off this panel into a separate window with a paneLayout
as the parent of the panel. When queried this flag will return if the
panel has been torn off into its own window.
|
|
-tearOffCopy(-toc)
|
string
|
|
|
Will create this panel as a torn of copy of the specified source panel.
|
|
-type(-typ)
|
string
|
|
|
This flag specifies the type of scripted panel to create.
|
|
-unParent(-up)
|
|
|
|
Specifies that the panel should be removed from its layout.
This (obviously) cannot be used with query.
|
|
-useTemplate(-ut)
|
string
|
|
|
Force the command to use a command template other than
the current one.
|
|
Flag can appear in Create mode of command
|
Flag can appear in Edit mode of command
|
Flag can appear in Query mode of command
|
Flag can be used more than once in a command.
|
// define callbacks for this type and make it a unique type
// as we don't want two panels sharing the same global data.
scriptedPanelType
-ccb sampleCreateCallback
-icb sampleInitCallback
-acb sampleAddCallback
-rcb sampleRemoveCallback
-dcb sampleDeleteCallback
-scb sampleSaveStateCallback
-unique true
sampleScriptedPanelType;
global proc sampleCreateCallback(string $panelName) {
//
// Description:
// Create any editors unparented here and do
// any other initialization required.
//
// In this example we will only declare a global array to
// maintain some state information.
//
global float $gSampleState[5];
}
global proc sampleInitCallback(string $panelName) {
//
// Description:
// Re-initialize the panel on file -new or file -open.
//
// In this example we will only re-init the global array.
//
global float $gSampleState[];
$gSampleState[0] = 20.2;
$gSampleState[1] = 50.5;
$gSampleState[2] = 34.7;
$gSampleState[3] = 2.0;
$gSampleState[4] = 1.0;
}
global proc sampleAddCallback(string $panelName) {
//
// Description: Create UI and parent any editors.
//
global float $gSampleState[];
columnLayout -adj true topCol;
separator -style "none" -h 10;
frameLayout -l "Sliders" -mw 10;
columnLayout -adj true sampleCol;
separator -style "none" -h 10;
floatSliderGrp -l "Property A" -f true
-v $gSampleState[0]
fsg1;
floatSliderGrp -l "Property B" -f true
-v $gSampleState[1]
fsg2;
floatSliderGrp -l "Property C" -f true
-v $gSampleState[2]
fsg3;
separator -style "none" -h 10;
setParent ..;
setParent ..;
separator -style "none" -h 10;
frameLayout -l "Radio Buttons" -mw 10;
columnLayout sampleCol2;
separator -style "none" -h 10;
radioButtonGrp -nrb 3
-l "Big Options"
-la3 "Option 1" "Option 2" "Option 3"
-select $gSampleState[3]
rbg;
radioButtonGrp -nrb 3
-l "Little Options"
-la3 "Option 4" "Option 5" "Option 6"
-select $gSampleState[4]
rbg2;
separator -style "none" -h 10;
}
global proc sampleRemoveCallback(string $panelName) {
//
// Description:
// Unparent any editors and save state if required.
//
global float $gSampleState[];
// Scope the control names to this panel.
//
string $control = `scriptedPanel -q -control $panelName`;
setParent $control;
$gSampleState[0] = `floatSliderGrp -q -v fsg1`;
$gSampleState[1] = `floatSliderGrp -q -v fsg2`;
$gSampleState[2] = `floatSliderGrp -q -v fsg3`;
$gSampleState[3] = `radioButtonGrp -q -sl rbg`;
$gSampleState[4] = `radioButtonGrp -q -sl rbg2`;
}
global proc sampleDeleteCallback(string $panelName) {
//
// Description:
// Delete any editors and do any other cleanup required.
}
global proc string sampleSaveStateCallback(string $panelName) {
//
// Description:
// Return a string that will restore the current state
// when it is executed.
global float $gSampleState[];
$indent = "\n\t\t\t";
return ($indent+"$gSampleState[0]="+$gSampleState[0]+";" +
$indent+"$gSampleState[1]="+$gSampleState[1]+";" +
$indent+"$gSampleState[2]="+$gSampleState[2]+";" +
$indent+"$gSampleState[3]="+$gSampleState[3]+";" +
$indent+"$gSampleState[4]="+$gSampleState[4]+";" +
$indent+"setSamplePanelState $panelName;\n" );
}
global proc setSamplePanelState( string $whichPanel ) {
//
// Description:
// This is a convenience proc to set the panel state from the
// global array
global float $gSampleState[];
// Scope the control names to this panel.
//
string $control = `scriptedPanel -q -control $whichPanel`;
if ("" != $control) {
setParent $control;
floatSliderGrp -e -v $gSampleState[0] fsg1;
floatSliderGrp -e -v $gSampleState[1] fsg2;
floatSliderGrp -e -v $gSampleState[2] fsg3;
if (0 != $gSampleState[3]) {
radioButtonGrp -e -sl $gSampleState[3] rbg;
};
if (0 != $gSampleState[4]) {
radioButtonGrp -e -sl $gSampleState[4] rbg2;
}
}
}
// This script will create an unparented scripted panel, place it
// in one window, remove it, and place it in another window then
// return it to the first window.
//
// Create unparented scripted panel
//
scriptedPanel -unParent -type sampleScriptedPanelType -label "Sample" sampleScriptedPanel;
// Create a couple of windows and parent the scripted panel to the first.
//
window sampleWin;
frameLayout -lv false -bv false frm;
scriptedPanel -e -parent "sampleWin|frm" sampleScriptedPanel;
showWindow;
window -w `window -q -w sampleWin` -h `window -q -h sampleWin` sampleWin2;
frameLayout -lv false -bv false frm;
showWindow;
// Reparent the scripted panel to the second window.
//
scriptedPanel -e -unParent sampleScriptedPanel;
scriptedPanel -e -parent "sampleWin2|frm" sampleScriptedPanel;
// Reparent the scripted panel back to the first window.
//
scriptedPanel -e -unParent sampleScriptedPanel;
scriptedPanel -e -parent "sampleWin|frm" sampleScriptedPanel;
// Close both windows
//
catch (`window -e -visible false sampleWin`);
catch (`window -e -visible false sampleWin2`);
// The scripted panel should appear in the Panel menu. Select
// Panels->Panel->Sample and the panel should appear in the main window.
//
// This second example shows how to use the saveState and copyState callbacks.
// saveStateCallback enables a panel to restore its state from a saved scene file.
// copyStateCallback enables a 'tear off copy' of a panel to copy its state from the original.
// print statements have been left in as an instructional aid - you would remove these in a
// real use case.
global proc meCreateCallback(string $panelName) {
// Create callback: create the editor.
print( "create " + $panelName + "\n" );
string $me = $panelName + "_me";
$me = `modelEditor -unParent $me`;
modelEditor -e -da "smoothShaded" -wos 1 $me;
}
global proc meInitCallback(string $panelName) {
// Init callback: allow re-initialisation (not used here).
print( "init " + $panelName + "\n" );
}
global proc meAddCallback(string $panelName) {
// Add callback: add editor into a panel layout.
// In this example we add a formLayout and two buttons,
// allowing the user to change the "wireframe on shaded" mode of the viewer.
print( "add " + $panelName + "\n" );
string $me = $panelName + "_me";
string $layout = `formLayout`;
modelEditor -e -parent $layout $me;
string $cmd = "modelEditor -e -wos 1 " + $me;
string $wos1 = `button -parent $layout -label "WOS 1" -c $cmd`;
$cmd = "modelEditor -e -wos 0 " + $me;
string $wos0 = `button -parent $layout -label "WOS 0" -c $cmd`;
formLayout -e -af $wos1 "top" 0 -af $wos1 "left" 0 $layout;
formLayout -e -af $wos0 "left" 0 -ac $wos0 "top" 0 $wos1 $layout;
formLayout -e -af $me "top" 0 -af $me "bottom" 0 -ac $me "left" 5 $wos1 -af $me "right" 0 $layout;
}
global proc meRemoveCallback(string $panelName) {
// Remove callback: unparent the editor from the layout.
print( "remove " + $panelName + "\n" );
string $me = $panelName + "_me";
modelEditor -e -unParent $me;
}
global proc meDeleteCallback(string $panelName) {
// Delete callback: delete the editor.
print( "delete " + $panelName + "\n" );
string $me = $panelName + "_me";
deleteUI $me;
}
global proc string meSaveStateCallback(string $panelName) {
// Save state callback: return a MEL command string that will restore the state of a recreated panel.
print( "save state " + $panelName + "\n" );
string $me = $panelName + "_me";
int $wos = `modelEditor -q -wos $me`;
return "modelEditor -e -wos " + $wos + " " + $me;
}
global proc meCopyStateCallback(string $panelName, string $newPanelName) {
// Copy state callback: copy the editor's state to the new instance of the panel type.
print( "copy state " + $panelName + ", " + $newPanelName + "\n" );
string $me = $panelName + "_me";
string $newMe = $newPanelName + "_me";
int $wos = `modelEditor -q -wos $me`;
modelEditor -e -wos $wos $newMe;
}
// Create the scripted panel type.
string $spType = `
scriptedPanelType
-ccb meCreateCallback
-icb meInitCallback
-acb meAddCallback
-rcb meRemoveCallback
-dcb meDeleteCallback
-scb meSaveStateCallback
-ocb meCopyStateCallback
meSpType
`;
print( "type is " + $spType + "\n" );
// As a test, create a window containing an instance of our new panel type.
// This panel will then be selectable from the Panels menu of any other panel.
// You can also create new instances of the scripted panel type via the Panel Editor,
// which again is available from the Panels menu of all panels.
window;
string $form = `formLayout`;
string $p = `scriptedPanel -type $spType -label "test panel"`;
formLayout -e -af $p "top" 0 -af $p "bottom" 0 -af $p "left" 0 -af $p "right" 0 $form;
showWindow;