pymel.core.windows.scriptedPanelType

scriptedPanelType(*args, **kwargs)

This command defines the callbacks for a type of scripted panel. The panel type created by this command is then used when creating a scripted panel. See also the ‘scriptedPanel’ command.

Flags:
Long name (short name) Argument Types Properties
addCallback (acb) unicode ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 

This flag specifies the callback procedure for adding the panel to a particular control layout. The parent layout is guaranteed to be the current default layout when the proc is called. If its name is required then it can be queried with ‘setParent -q’. Any editors should be parented here. global proc procName (string $panelName) { ....

copyStateCallback (ocb) unicode ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 

This flag specifies the callback procedure for copying the state of the panel when a tear-off copy of the panel is made. The callback proc has the form: global proc procName (string $panelName, string $newPanelName) { .... } This procedure will be executed immediately after the addCallback procedure has finished executing. At that point, the copied panel will be fully created and accessible to facilitate copying of panel settings. Note: the addCallback procedure is called after the createCallback procedure has been called.

createCallback (ccb) unicode ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 

This flag specifies the callback procedure for initially creating the panel object. No UI should be created here. Any editors owned by the panel should be created here unparented. The callback proc has the form: global proc procName (string $panelName) { ....

customView (cv) bool ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 

This flag specifies if this view is a custom 3d view for MPx3dModelView types. This flag should only be used for MPx3dModelView types.Flag can appear in Create mode of commandFlag can have multiple arguments, passed either as a tuple or a list.

defineTemplate (dt) unicode ../../../_images/create.gif
 

Puts a 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.

deleteCallback (dcb) unicode ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
This flag specifies the callback procedure for final deletion of the panel. The callback proc has the form: global proc procName (string $panelName) { ....
exists (ex) bool ../../../_images/create.gif
 
Returns true|false depending upon whether the specified object exists. Other flags are ignored.
initCallback (icb) unicode ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 

This flag specifies the callback procedure for the initialize callback. This will be called on file -new and file -open to give the panel an opportunity to re- initialize to a starting state, if required. The panel may be parented or unparented at this time. The callback proc has the form: global proc procName (string $panelName) { ....

label (l) unicode  
   
obsolete (o) bool ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
This flag specifies that this type is no longer used in Maya.
removeCallback (rcb) unicode ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 

This flag specifies the callback procedure for removing the panel from its current control layout. Any editors should be unparented here. The callback proc has the form: global proc procName (string $panelName) { ....

retainOnFileOpen (rfo) bool ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
This flag specifies if panels of this type should be retained after restoring panel cofiguration during file open. Default value is false.
saveStateCallback (scb) unicode ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 

This flag specifies the callback procedure for saving the state of the panel. The callback proc has the form: global proc string procName (string $panelName) { .... } Note that the proc returns a string. This string will be executed after the createCallback has been called to facilitate restoring the panel state.

unique (u) bool ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
This flag specifies if only one instance of this type of panel can exist at a given time.
useTemplate (ut) unicode ../../../_images/create.gif
 
Force the command to use a command template other than the current one.

Derived from mel command maya.cmds.scriptedPanelType

Example:

import pymel.core as pm

import maya.cmds as cmds

// NOTE: The scriptedPanelType command does not support python
//               callbacks; these callbacks must be MEL.


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;
           }
       }
}

# Below is the python code to create and use scriptedPanelType and scriptedPanel using the MEL
# callbacks defined above.

# Use unique flag as we don't want two panels sharing the same global data.
pm.scriptedPanelType( 'sampleScriptedPanelType', ccb='sampleCreateCallback', icb='sampleInitCallback', acb='sampleAddCallback', rcb='sampleRemoveCallback', dcb='sampleDeleteCallback', scb='sampleSaveStateCallback', unique=True )

#  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
#
pm.scriptedPanel( 'sampleScriptedPanel', unParent=True, type='sampleScriptedPanelType', label='Sample' )

#    Create a couple of windows and parent the scripted panel to the first.
#
pm.window( 'sampleWin' )
pm.frameLayout( 'frm', lv=False, bv=False )
pm.scriptedPanel( 'sampleScriptedPanel', e=True, parent='sampleWin|frm' )
pm.showWindow()

pm.window( 'sampleWin2', w=pm.window('sampleWin', q=True, w=True), h=pm.window('sampleWin', q=True, h=True) )
pm.frameLayout( 'frm', lv=False, bv=False )
pm.showWindow()

#    Reparent the scripted panel to the second window.
#
pm.scriptedPanel( 'sampleScriptedPanel', e=True, unParent=True )
pm.scriptedPanel( 'sampleScriptedPanel', e=True, parent='sampleWin2|frm' )

#    Reparent the scripted panel back to the first window.
#
pm.scriptedPanel( 'sampleScriptedPanel', e=True, unParent=True )
pm.scriptedPanel( 'sampleScriptedPanel', e=True, parent='sampleWin|frm' )

#    Close both windows
#
pm.window( 'sampleWin', e=True, visible=False )
pm.window( 'sampleWin2', e=True, visible=False )

#    The scripted panel should appear in the Panel menu.  Select
#    Panels-"Panel-"Sample and the panel should appear in the main window.
#

Previous topic

pymel.core.windows.scriptedPanel

Next topic

pymel.core.windows.scrollField

Core

Core Modules

Other Modules

This Page