Python maya.cmds.getPanel() Examples

The following are 16 code examples of maya.cmds.getPanel(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module maya.cmds , or try the search function .
Example #1
Source File: capture.py    From pyblish-bumpybox with GNU Lesser General Public License v3.0 6 votes vote down vote up
def parse_active_panel():
    """Parse the active modelPanel.

    Raises
        RuntimeError: When no active modelPanel an error is raised.

    Returns:
        str: Name of modelPanel

    """

    panel = cmds.getPanel(withFocus=True)

    # This happens when last focus was on panel
    # that got deleted (e.g. `capture()` then `parse_active_view()`)
    if not panel or "modelPanel" not in panel:
        raise RuntimeError("No active model panel found")

    return panel 
Example #2
Source File: capture.py    From maya-capture with MIT License 6 votes vote down vote up
def parse_active_panel():
    """Parse the active modelPanel.

    Raises
        RuntimeError: When no active modelPanel an error is raised.

    Returns:
        str: Name of modelPanel

    """

    panel = cmds.getPanel(withFocus=True)

    # This happens when last focus was on panel
    # that got deleted (e.g. `capture()` then `parse_active_view()`)
    if not panel or "modelPanel" not in panel:
        raise RuntimeError("No active model panel found")

    return panel 
Example #3
Source File: ml_utilities.py    From ml_tools with MIT License 6 votes vote down vote up
def getModelPanel():
    '''Return the active or first visible model panel.'''
    
    panel = mc.getPanel(withFocus=True)

    if mc.getPanel(typeOf=panel) != 'modelPanel':
        #just get the first visible model panel we find, hopefully the correct one.
        panels = getModelPanels()
        if panels:
            panel = panels[0]
            mc.setFocus(panel)
    
    if mc.getPanel(typeOf=panel) != 'modelPanel':
        OpenMaya.MGlobal.displayWarning('Please highlight a camera viewport.')
        return None
    return panel 
Example #4
Source File: ViewportPainter.py    From mViewportDrawOpenGL with MIT License 5 votes vote down vote up
def initializeCallback(self):

        #get current model panel
        self.currentModelPanel = cmds.getPanel(wf = 1)
        if "modelPanel" not in self.currentModelPanel:
            self.currentModelPanel = cmds.getPanel(vis = 1)
            for i in self.currentModelPanel:
                if "modelPanel" in i:
                    self.currentModelPanel = i


        #try removing old callbacks from memory
        try:
            OpenMayaUI.MUiMessage.removeCallback(self.callBack)
        except:
            pass

        #create a callback that is registered after a frame is drawn with a 3D content but before 2D content
        self.callback = OpenMayaUI.MUiMessage.add3dViewPostRenderMsgCallback(self.currentModelPanel, self.update)
        self.view3D.refresh(True, True)

        #create QT maya window event filter
        main_window_ptr = OpenMayaUI.MQtUtil.mainWindow()
        self.qt_Maya_Window = wrapInstance(long(main_window_ptr), QtCore.QObject)
        self.qt_Maya_Window.installEventFilter(self.userKeyboardEvents) 

        #create viewport event filter
        active_view_ptr = self.view3D.widget()
        self.qt_Active_View = wrapInstance(long(active_view_ptr), QtCore.QObject)
        self.qt_Active_View.installEventFilter(self.userMouseEvents)

        cmds.inViewMessage( amg='<hl>Tool:</hl> Use <hl>"Esc"</hl> to cancel the tool', pos='botLeft', fade=True )

        print "Initialized..." 
Example #5
Source File: panels.py    From mGui with MIT License 5 votes vote down vote up
def get_current_panel(cls):
        current = cmds.getPanel(wf=True)
        try:
            return cls.get(current)
        except RuntimeError:
            return None 
Example #6
Source File: panels.py    From mGui with MIT License 5 votes vote down vote up
def get(cls, panel_string):
        ptype = cmds.getPanel(typeOf=panel_string)
        pfclass = cls.TYPES.get(ptype, None)
        if not pfclass:
            raise RuntimeError("Unknown panel type: {}".format(ptype))
        return pfclass.wrap(panel_string, panel_string) 
Example #7
Source File: mqtutil.py    From tutorials with MIT License 5 votes vote down vote up
def getWidgetUnderPointer():
	panel = cmds.getPanel(underPointer=True)
	if not panel:
		return None

	ptr = mui.MQtUtil.findControl(panel)
	widget = sip.wrapinstance(long(ptr), QtCore.QObject)
	return widget 
Example #8
Source File: ml_graphEditorMask.py    From ml_tools with MIT License 5 votes vote down vote up
def getGraphEditorOutliner():
    graphEditor = mc.getPanel(scriptType='graphEditor')
    if graphEditor:
        return mc.animCurveEditor(graphEditor[0]+'GraphEd', query=True, outliner=True)
    return None 
Example #9
Source File: ml_graphEditorMask.py    From ml_tools with MIT License 5 votes vote down vote up
def showAll(*args):

    try:
        mc.delete(ATTR_FILTER_NAME)
    except:pass

    for ge in mc.getPanel(scriptType='graphEditor'):
        mm.eval('filterUIClearFilter  {};'.format(mc.animCurveEditor(ge+'GraphEd', query=True, outliner=True))) 
Example #10
Source File: ml_utilities.py    From ml_tools with MIT License 5 votes vote down vote up
def getCurrentCamera():
    '''
    Returns the camera that you're currently looking through.
    If the current highlighted panel isn't a modelPanel,
    '''

    panel = mc.getPanel(withFocus=True)

    if mc.getPanel(typeOf=panel) != 'modelPanel':
        #just get the first visible model panel we find, hopefully the correct one.
        for p in mc.getPanel(visiblePanels=True):
            if mc.getPanel(typeOf=p) == 'modelPanel':
                panel = p
                mc.setFocus(panel)
                break

    if mc.getPanel(typeOf=panel) != 'modelPanel':
        OpenMaya.MGlobal.displayWarning('Please highlight a camera viewport.')
        return False

    camShape = mc.modelEditor(panel, query=True, camera=True)
    if not camShape:
        return False

    camNodeType = mc.nodeType(camShape)
    if mc.nodeType(camShape) == 'transform':
        return camShape
    elif mc.nodeType(camShape) in ['camera','stereoRigCamera']:
        return mc.listRelatives(camShape, parent=True, path=True)[0] 
Example #11
Source File: ml_utilities.py    From ml_tools with MIT License 5 votes vote down vote up
def getModelPanels():
    '''Return all the model panels visible so you can operate on them.'''
    panels = []
    for p in mc.getPanel(visiblePanels=True):
        if mc.getPanel(typeOf=p) == 'modelPanel':
            panels.append(p)
    return panels 
Example #12
Source File: ml_utilities.py    From ml_tools with MIT License 5 votes vote down vote up
def visibleInGraphEditor(self):
        '''
        Initializes the keySelection object with curves visibile in graph editor.
        Returns True if successful.
        '''


        if not 'graphEditor1' in mc.getPanel(visiblePanels=True):
            return False

        graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True)

        if not graphVis:
            return False

        for each in graphVis:
            try:
                self._curves.extend(mc.keyframe(each, query=True, name=True))
            except StandardError:
                pass


        if not self._curves:
            return False

        return True 
Example #13
Source File: canvas.py    From spore with MIT License 4 votes vote down vote up
def enter_widget(self):
        """ set focuts to the panel under the cursor """

        panel = cmds.getPanel(underPointer=True)
        cmds.setFocus(panel)
        self.setFocus() 
Example #14
Source File: preformat.py    From mGui with MIT License 4 votes vote down vote up
def generate_panels(filename):
    with open(filename, 'wt') as filehandle:
        filehandle.write("'''\nmGui wrapper classes\n\nAuto-generated wrapper classes for use with mGui\n'''\n\n")
        filehandle.write('''
        import maya.cmds as cmds
        from mGui.core import Control
        from mGui.core.editors import EditorFactory
        from mGui.properties import WrappedCtlProperty
        def make_editor_command(cmd, editorString):
            return WrappedCtlProperty(editorString, cmd, True, EditorFactory.get)
        ''')

        for each_class in constants.PANEL_COMMANDS:
            try:
                filehandle.write(PanelInfo.from_command(each_class).template())
                filehandle.write('\n\n')

            except RuntimeError:
                filehandle.write("# command '%s' not present in this maya" % each_class)



        filehandle.write('''
        class PanelFactory(object):
            TYPES = {
                'modelPanel': ModelPanel,
                'hardwareRenderPanel': HardwareRenderPanel,
                'hyperGraph': HyperGraph,
                'hyperPanel': HyperPanel,
                'hyperShade': HyperShade,
                'nodeOutliner': NodeOutliner,
                'outlinerPanel': OutlinerPanel,
                'panelConfiguration': PanelConfiguration,
                'panelHistory': PanelHistory,
                'scriptedPanel': ScriptedPanel,
                'spreadSheetEditor': SpreadSheetEditor,
                'visor': Visor
            }

            @classmethod
            def get_current_panel(cls):
                current = cmds.getPanel(wf=True)
                try:
                    return cls.get(current)
                except RuntimeError:
                    return None

            @classmethod
            def get(cls, panel_string):
                ptype = cmds.getPanel(typeOf=panel_string)
                pfclass = cls.TYPES.get(ptype, None)
                if not pfclass:
                    raise RuntimeError("Unknown panel type: {}".format(ptype))
                return pfclass.wrap(panel_string, panel_string)\n''') 
Example #15
Source File: ml_frameGraphEditor.py    From ml_tools with MIT License 4 votes vote down vote up
def frameGraphEditor(centerCurrentTime=False):
    '''
    If graph editor has focus, frame the selected or visible animation curves.
    '''

    panel = mc.getPanel(up=True)
    if not panel:
        panel = mc.getPanel(withFocus=True)
    if not panel:
        return False
    panelType = mc.getPanel(to=panel)
    if panelType != 'scriptedPanel':
        return False
    scriptedType = mc.scriptedPanel(panel, query=True, type=True)
    if scriptedType != 'graphEditor':
        return False

    graphEditor = panel+'GraphEd'

    keySel = utl.KeySelection()
    if keySel.selectedKeys():
        pass
    elif keySel.visibleInGraphEditor():
        pass

    if keySel.selected:
        times = keySel.getSortedKeyTimes()
        start = times[0]
        end = times[-1]
    else:
        keySel.frameRange()
        start = keySel._timeRangeStart
        end = keySel._timeRangeEnd

    values = sorted(keySel.keyframe(query=True, valueChange=True))
    minValue = values[0]
    maxValue = values[-1]

    if start == end:
        start = start-1
        end = end+1

    if maxValue == minValue:
        minValue = minValue-0.5
        maxValue = maxValue+0.5

    #add a 10% padding
    timePadding = (end-start)/10.0
    valuePadding = (maxValue-minValue)/10.0

    mc.animView(graphEditor, startTime=start-timePadding, endTime=end+timePadding, minValue=minValue-valuePadding, maxValue=maxValue+valuePadding)

    if centerCurrentTime:
        mc.animCurveEditor(graphEditor, edit=True, lookAt='currentTime')

    return True 
Example #16
Source File: lib.py    From maya-capture-gui with MIT License 4 votes vote down vote up
def get_current_camera():
    """Returns the currently active camera.

    Searched in the order of:
        1. Active Panel
        2. Selected Camera Shape
        3. Selected Camera Transform

    Returns:
        str: name of active camera transform

    """

    # Get camera from active modelPanel  (if any)
    panel = cmds.getPanel(withFocus=True)
    if cmds.getPanel(typeOf=panel) == "modelPanel":
        cam = cmds.modelEditor(panel, query=True, camera=True)
        # In some cases above returns the shape, but most often it returns the
        # transform. Still we need to make sure we return the transform.
        if cam:
            if cmds.nodeType(cam) == "transform":
                return cam
            # camera shape is a shape type
            elif cmds.objectType(cam, isAType="shape"):
                parent = cmds.listRelatives(cam, parent=True, fullPath=True)
                if parent:
                    return parent[0]

    # Check if a camShape is selected (if so use that)
    cam_shapes = cmds.ls(selection=True, type="camera")
    if cam_shapes:
        return cmds.listRelatives(cam_shapes,
                                  parent=True,
                                  fullPath=True)[0]

    # Check if a transform of a camShape is selected
    # (return cam transform if any)
    transforms = cmds.ls(selection=True, type="transform")
    if transforms:
        cam_shapes = cmds.listRelatives(transforms, shapes=True, type="camera")
        if cam_shapes:
            return cmds.listRelatives(cam_shapes,
                                      parent=True,
                                      fullPath=True)[0]