def setThreePanelLayout(): shotCamera = animMod.getShotCamera() if not shotCamera: shotCamera = "persp" mel.eval("toolboxChangeQuickLayoutButton \"Persp/Graph/Hypergraph\" 2;"+\ #"ThreeTopSplitViewArrangement;"+\ "lookThroughModelPanel %s hyperGraphPanel2;"%shotCamera+\ "lookThroughModelPanel persp modelPanel4;") #"scriptedPanel -e -rp modelPanel2 graphEditor1;") viewports = [view for view in cmds.getPanel(type='modelPanel') if view in cmds.getPanel(visiblePanels=True)] defaultCameras = [u'front', u'persp', u'side', u'top'] for view in viewports: camera = utilMod.getCamFromSelection([cmds.modelEditor(view, query=True, camera=True)]) cameraTransform = camera[0] cameraShape = camera[1] if cameraTransform in defaultCameras: utilMod.animViewportViewMode(view) if cameraTransform == "persp": cmds.camera(cameraTransform, edit=True, orthographic=False) cmds.setAttr("%s.nearClipPlane"%cameraShape, 1000) cmds.setAttr("%s.farClipPlane"%cameraShape, 10000000) cmds.setAttr("%s.focalLength"%cameraShape, 3500) else: utilMod.cameraViewMode(view) cmds.setAttr("%s.displayFilmGate"%cameraShape, 1) cmds.setAttr("%s.overscan"%cameraShape, 1)
def replaceWithCurrentView(self, assetName): thumbPath = os.path.join(self.directory, assetName, "%s_thumb.jpg" % assetName) SSpath = os.path.join(self.directory, assetName, "%s_s.jpg" % assetName) WFpath = os.path.join(self.directory, assetName, "%s_w.jpg" % assetName) pbPanel = cmds.getPanel(wf=True) if cmds.getPanel(to=pbPanel) != "modelPanel": cmds.warning("The focus is not on a model panel. Cancelling") return None, None, None wireMode = cmds.modelEditor(pbPanel, q=1, wireframeOnShaded=1) textureMode = cmds.modelEditor(pbPanel, q=1, displayTextures=1) cmds.setAttr("defaultRenderGlobals.imageFormat", 8) # This is the value for jpeg frame = cmds.currentTime(query=True) # thumb cmds.modelEditor(pbPanel, e=1, displayTextures=1) cmds.modelEditor(pbPanel, e=1, wireframeOnShaded=0) cmds.playblast(completeFilename=thumbPath, forceOverwrite=True, format='image', width=200, height=200, showOrnaments=False, frame=[frame], viewer=False) # screenshot cmds.playblast(completeFilename=SSpath, forceOverwrite=True, format='image', width=1600, height=1600, showOrnaments=False, frame=[frame], viewer=False) # Wireframe cmds.modelEditor(pbPanel, e=1, displayTextures=0) cmds.modelEditor(pbPanel, e=1, wireframeOnShaded=1) cmds.playblast(completeFilename=WFpath, forceOverwrite=True, format='image', width=1600, height=1600, showOrnaments=False, frame=[frame], viewer=False) # leave it as it was cmds.modelEditor(pbPanel, e=1, wireframeOnShaded=wireMode) cmds.modelEditor(pbPanel, e=1, displayTextures=textureMode)
def __set_renderer_by_str(self, value): """ This function sets the active rendere from it s string name @param value: str, the name of the rendere """ currPanel = cmds.getPanel(withFocus=1) panelType = cmds.getPanel(to=currPanel) if value in self.RENDERERS_SHORTCUT: #create the mel command to eval cmd = 'setRendererInModelPanel \"{r}\" {cp};'.format( r=self.RENDERERS_SHORTCUT[value], cp=currPanel) #make sure we have a model panel active if (panelType == "modelPanel"): mel.eval(cmd) else: OpenMaya.MGlobal.displayError( "In order to set stuff" + " on the viewport we need an acive viewport") else: #print the error strSupp = [str(k) for k in self.RENDERERS_SHORTCUT.keys()] supp = "\n-" + "\n- ".join(strSupp) OpenMaya.MGlobal.displayError( "You did not provide a valid " + "renderer name, supported renderer names are :" + " \n {r}".format(r=supp) + " \n got {v}".format(v=type(value).__name__))
def desIsolate(): """desisolate""" currPanel = mc.getPanel(withFocus=True) panelType = mc.getPanel(to=currPanel) if panelType == 'modelPanel': mc.isolateSelect(currPanel, state=0) mm.eval('enableIsolateSelect %s 0;' % currPanel)
def getActiveModelPanel(): '''gets the string of the active model editor panel (3D viewport returns none if none is active''' activePanel = cmds.getPanel(wf=True) if cmds.getPanel(typeOf=activePanel) == 'modelPanel': return activePanel else: return cmds.playblast(ae=True)
def isolate(self): """isolate node in viewport""" currPanel = mc.getPanel(withFocus=True) panelType = mc.getPanel(to=currPanel) if panelType == 'modelPanel': self() mc.isolateSelect(currPanel, state=1)
def get_current_camera(): ''' ''' camera = 'persp' if OpenMaya.MGlobal.mayaState() == OpenMaya.MGlobal.kInteractive: panels = mc.getPanel(vis=True) for pan in panels: if pan not in mc.getPanel(typ='modelPanel'): continue cam = mc.modelPanel(pan, q=True, cam=True) if mc.nodeType(cam) != 'transform': cam = mc.listRelatives(cam, p=True)[0] if cam not in ('persp', 'top', 'front', 'side'): camera = cam mc.modelEditor(pan, e=True, alo=False) mc.modelEditor(pan, e=True, pm=True, av=True, da='smoothShaded') break else: for cam in mc.listRelatives(mc.ls(cameras=True), p=True): if mc.getAttr('{0}.renderable'.format(cam)): camera = cam break return camera
def isGraphEditorActive(): '''Returns a tuple of (graphEditorState, graphEditorPanel). GraphEditorState is true if the cursor is over the graph editor, and false if it is not, or if the cursor can not be queried. The graphEditorPanel will default to 'graphEditor1' if no graph editor is found under the mouse.''' # Find out if the graph editor is under cursor graphEditorActive = 0 panel = '' try: panel = cmd.getPanel(underPointer=True) except TypeError: # Maya is being bitchy again. Default to channelBox and warn # the user that Maya is a bitch. Yes, I've had this fail here # before. Maya told me underPointer needed to be passed a bool. # Well, I hate to tell you Maya, but True is a bool. panel = None om.MGlobal.displayWarning("Defaulting to channelBox because Maya doesn't know where your cursor is.") if panel and cmd.getPanel(typeOf=panel) == 'scriptedPanel': # I assume that testing for the type will be more accurate than matching the panel strings if cmd.scriptedPanel(panel, q=1, type=1) == 'graphEditor': graphEditorActive = 1 # A graph editor panel should always be passed, even if we couldn't find a specific one. if not graphEditorActive: panel = 'graphEditor1' return graphEditorActive, panel
def is_graph_editor(): """ Determine if keys are selected in the Graph Editor or Dope Sheet. :returns: True or False whether keys are selected in the Graph Editor or Dope Sheet :rtype: bool """ sl_list = om.MGlobal.getActiveSelectionList() it = om.MItSelectionList(sl_list, om.MFn.kAnimCurve) visible_panels = cmds.getPanel(vis=True) graph_panels = cmds.getPanel(sty='graphEditor') dope_panels = cmds.getPanel(sty='dopeSheetPanel') if graph_panels is not None: graph_vis = any(x in graph_panels for x in visible_panels) else: graph_vis = False if dope_panels is not None: dope_vis = any(x in dope_panels for x in visible_panels) else: dope_vis = False return not it.isDone() and (graph_vis or dope_vis)
def get_panel_type(): ''' returns type of panel under focus ''' current_panel = cmds.getPanel(withFocus=True) current_panel_type = cmds.getPanel(typeOf=current_panel) return current_panel_type
def getPanel(): isModelPanel = False panel = cmds.getPanel(withFocus=True) panelType = cmds.getPanel(typeOf=panel) if panelType == "modelPanel": isModelPanel = True return isModelPanel, panel
def desIsolate(): """desisolate""" currPanel = mc.getPanel( withFocus = True ); panelType = mc.getPanel( to = currPanel ) if panelType == 'modelPanel': mc.isolateSelect( currPanel, state = 0 ) mm.eval( 'enableIsolateSelect %s 0;'%currPanel )
def getActiveViewport(): activePanel = cmds.getPanel(withFocus=True) panelType = cmds.getPanel(typeOf=activePanel) if not panelType == 'modelPanel': cmds.warning('No viewport active') return return activePanel
def getAllViewports(): return [ view for view in cmds.getPanel(type='modelPanel') if view in cmds.getPanel( visiblePanels=True) and view != "scriptEditorPanel1" ]
def isolate(self): """isolate node in viewport""" currPanel = mc.getPanel( withFocus = True ) panelType = mc.getPanel( to = currPanel ) if panelType == 'modelPanel': self() mc.isolateSelect( currPanel, state = 1 )
def main(b_isolate=True): active_panel = cmds.getPanel(wf=True) model_panel = cmds.getPanel(typ='modelPanel') src_panel = None if active_panel and active_panel in model_panel: src_panel = active_panel if src_panel: iso_state = cmds.isolateSelect(src_panel, q=True, state=True) isExist = True if b_isolate: if iso_state == False: isExist = False mel.eval('enableIsolateSelect "%s" 1;'%src_panel) selected = cmds.ls(sl=True) if selected: view_object = cmds.isolateSelect(src_panel, q=True, vo=True) if view_object: set_members = cmds.sets(view_object, q=True) if set_members == None: set_members = [] for sel in selected: cmds.select(sel,r=True) if sel in set_members and isExist == True: cmds.isolateSelect(src_panel, rs=True) else: cmds.isolateSelect(src_panel, addSelected=True) cmds.isolateSelect(src_panel,u=True) cmds.select(selected, r=True) elif b_isolate == False and iso_state: cmds.isolateSelect(src_panel, state=False)
def main(b_isolate=True): active_panel = cmds.getPanel(wf=True) model_panel = cmds.getPanel(typ='modelPanel') src_panel = None if active_panel and active_panel in model_panel: src_panel = active_panel if src_panel: iso_state = cmds.isolateSelect(src_panel, q=True, state=True) isExist = True if b_isolate: if iso_state == False: isExist = False mel.eval('enableIsolateSelect "%s" 1;' % src_panel) selected = cmds.ls(sl=True) if selected: view_object = cmds.isolateSelect(src_panel, q=True, vo=True) if view_object: set_members = cmds.sets(view_object, q=True) if set_members == None: set_members = [] for sel in selected: cmds.select(sel, r=True) if sel in set_members and isExist == True: cmds.isolateSelect(src_panel, rs=True) else: cmds.isolateSelect(src_panel, addSelected=True) cmds.isolateSelect(src_panel, u=True) cmds.select(selected, r=True) elif b_isolate == False and iso_state: cmds.isolateSelect(src_panel, state=False)
def pre_command(with_focus=False, **flags): """ :param with_focus: only affect the panel with focus :param flags: for mc.modelEditor :return: list of affected panels """ global SCENE_PANEL_VALUES SCENE_PANEL_VALUES.clear() panels = mc.getPanel(type='modelPanel') if with_focus: focused_panel = mc.getPanel(withFocus=True) if focused_panel not in panels: # is this even possible? logger.debug('focused_panel: "{0}" not a modelPanel: [{1}]'.format( focused_panel, panels)) return [] panels = [focused_panel] for panel in panels: for flag, value in flags.iteritems(): scene_value = mc.modelEditor(panel, q=True, **{flag: True}) if scene_value != value: mc.modelEditor(panel, e=True, **{flag: value}) SCENE_PANEL_VALUES[panel][flag] = scene_value return panels
def setThreePanelLayout(): shotCamera = animMod.getShotCamera() if not shotCamera: shotCamera = "persp" mel.eval("toolboxChangeQuickLayoutButton \"Persp/Graph/Hypergraph\" 2;"+\ #"ThreeTopSplitViewArrangement;"+\ "lookThroughModelPanel %s hyperGraphPanel2;"%shotCamera+\ "lookThroughModelPanel persp modelPanel4;") #"scriptedPanel -e -rp modelPanel2 graphEditor1;") viewports = [ view for view in cmds.getPanel(type='modelPanel') if view in cmds.getPanel(visiblePanels=True) ] defaultCameras = [u'front', u'persp', u'side', u'top'] for view in viewports: camera = utilMod.getCamFromSelection( [cmds.modelEditor(view, query=True, camera=True)]) cameraTransform = camera[0] cameraShape = camera[1] if cameraTransform in defaultCameras: utilMod.animViewportViewMode(view) if cameraTransform == "persp": cmds.camera(cameraTransform, edit=True, orthographic=False) cmds.setAttr("%s.nearClipPlane" % cameraShape, 1000) cmds.setAttr("%s.farClipPlane" % cameraShape, 10000000) cmds.setAttr("%s.focalLength" % cameraShape, 3500) else: utilMod.cameraViewMode(view) cmds.setAttr("%s.displayFilmGate" % cameraShape, 1) cmds.setAttr("%s.overscan" % cameraShape, 1)
def dynSelection(self, *args, **kwargs): cmds.undoInfo(swf=False) #Stop Undo/Redo queue without flushing it! panel = cmds.getPanel(underPointer=True) panelType = cmds.getPanel(typeOf=panel) cursorPos = self.mousePos() if panelType == 'modelPanel': shapesUnderCursor = cmds.hitTest(panel, cursorPos[0], cursorPos[1]) if len(shapesUnderCursor) > 0: shape = cmds.ls(shapesUnderCursor, flatten=True)[0] if cmds.objectType(shape) == 'mnt_poseScope': if shape != self.oldShape: self.oldattrValue = cmds.getAttr(shape + '.opacity') if self.oldShape: cmds.setAttr(self.oldShape + '.opacity', self.oldattrValue) cmds.setAttr(shape + '.opacity', 0.15) self.oldShape = shape if len(shapesUnderCursor) == 0: if self.oldShape: cmds.setAttr(self.oldShape + '.opacity', self.oldattrValue) self.oldShape = None cmds.undoInfo(swf=True)
def toggleObjectDisplay(purpose): # get active and find type of panel currentPanel = cmds.getPanel(withFocus=True) panelType = cmds.getPanel(to=currentPanel) if panelType == 'modelPanel': # all off cmds.modelEditor(currentPanel, e=True, alo=0) # arguments if purpose == 'anim': # specific on cmds.modelEditor(currentPanel, e=True, nurbsCurves=1) cmds.modelEditor(currentPanel, e=True, polymeshes=1) cmds.modelEditor(currentPanel, e=True, locators=1) cmds.modelEditor(currentPanel, e=True, cameras=1) cmds.modelEditor(currentPanel, e=True, handles=1) message('Panel display set for animation') elif purpose == 'cam': # specific on cmds.modelEditor(currentPanel, e=True, cameras=1) cmds.modelEditor(currentPanel, e=True, polymeshes=1) message('Panel display set for camera') else: message('Current panel is of the wrong type')
def __set_renderer_by_str(self, value): """ This function sets the active rendere from it s string name @param value: str, the name of the rendere """ currPanel = cmds.getPanel(withFocus = 1) panelType = cmds.getPanel(to = currPanel) if value in self.RENDERERS_SHORTCUT: #create the mel command to eval cmd = 'setRendererInModelPanel \"{r}\" {cp};'.format( r = self.RENDERERS_SHORTCUT[value] , cp = currPanel) #make sure we have a model panel active if (panelType == "modelPanel"): mel.eval(cmd) else : OpenMaya.MGlobal.displayError("In order to set stuff" + " on the viewport we need an acive viewport") else : #print the error strSupp = [str(k) for k in self.RENDERERS_SHORTCUT.keys()] supp = "\n-" +"\n- ".join(strSupp) OpenMaya.MGlobal.displayError("You did not provide a valid " + "renderer name, supported renderer names are :" + " \n {r}".format(r = supp) + " \n got {v}".format(v= type(value).__name__))
def playblast(**kwargs): # Extract the camera from the active view. current_panel = cmds.getPanel(withFocus=True) panel_type = cmds.getPanel(typeOf=current_panel) if panel_type == 'modelPanel': camera = cmds.modelPanel(current_panel, query=True, camera=True) camera_attrs = dict((camera + '.' + k, v) for k, v in settings['camera_attrs'].iteritems()) else: cmds.warning( 'Current panel is not a modelling panel; playblasts will not correctly setup the camera' ) camera = None camera_attrs = {} # These should really be controlled elsewhere... kwargs.setdefault('widthHeight', (1280, 720)) kwargs.setdefault('offScreen', True) kwargs.setdefault('forceOverwrite', True) kwargs.setdefault('percent', 100) # So much state! Can we have Python2.7 now? with context.attrs(settings['attrs'], camera_attrs): with context.command(cmds.camera, camera, edit=True, **(settings['camera'] if camera else {})): with context.command(cmds.currentUnit, linear='cm', time='film'): return cmds.playblast(**kwargs)
def altFrame(*args): # cmds.nodeType(sel), object type # optimize, real slow pnl = cmds.getPanel(withFocus=True) typ = cmds.getPanel(typeOf=pnl) if typ == 'modelPanel': sel = cmds.ls(sl=True, fl=True) gs = ac.GraphSelection() locs = [] if sel: for item in sel: if cmds.objectType(item, i='transform') or cmds.objectType(item, i='joint'): loc = cn.locator(obj=item, ro='zxy', X=0.35, constrain=False, shape=False)[0] locs.append(loc) else: try: print cmds.listRelatives(item, parent=True)[0], '_______________' loc = cn.locator(obj=cmds.listRelatives(item, parent=True)[0], ro='zxy', X=0.35, constrain=False, shape=False) print loc, '_____________________' loc = loc[0] locs.append(loc) except: message('didnt frame object: ' + item) cmds.select(locs) mel.eval("fitPanel -selected;") cmds.delete(locs) gs.reselect() else: message('select an object') else: mel.eval("fitPanel -selected;")
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
def getCamera(self): panelWithFocus = m.getPanel(withFocus=True) panelType = m.getPanel(typeOf=panelWithFocus) if panelType != 'modelPanel': self.showError( 'Cannot find camera.' + (' ' * 100), 'Select perspective viewport with camera without animation or locked channels.' ) return None, None else: camera = m.modelPanel(panelWithFocus, q=True, camera=True) cameraShape = m.listRelatives(camera, shapes=True, fullPath=True) if m.getAttr(cameraShape[0] + '.orthographic'): self.showError( 'Cannot use orthographic camera.' + (' ' * 100), 'Select perspective viewport with camera without animation or locked channels.' ) return None, None attrsToCheck = ('.tx', '.ty', '.tz', '.rx', '.ry', '.rz') for attr in attrsToCheck: if m.getAttr(camera + attr, lock=True) or m.listConnections( camera + attr, s=True, d=False): self.showError('Cannot use this camera.' + (' ' * 50), 'This camera is locked or animated.') return None, None return camera, cameraShape[0]
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..."
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 if mc.nodeType(camShape) == 'transform': return camShape elif mc.nodeType(camShape) == 'camera': return mc.listRelatives(camShape, parent=True)[0]
def view(self,opt): panels=mc.getPanel(vis=1) for pane in panels: if mc.getPanel(to=pane) == 'modelPanel' : mc.modelEditor(pane,e=1,sel=True) mc.modelEditor(pane,e=1,sel=False) mc.modelEditor(pane,e=1,sel=True)
def __get_panel(): panels = cmds.getPanel(type='modelPanel') focus = cmds.getPanel(withFocus=True) if focus in panels: return focus pointer = cmds.getPanel(underPointer=True) if pointer in panels: return pointer
def getCurrentModelPanel(): currentModelPanel = mc.getPanel(wf=True) if "modelPanel" not in currentModelPanel: currentModelPanel = mc.getPanel(vis=True) for each in currentModelPanel: if "modelPanel" in each: currentModelPanel = each return currentModelPanel
def activePanel(): fpanel = mc.getPanel( wf=1 ) panelType = mc.getPanel( to=fpanel) if panelType == 'modelPanel': fpanel = mc.getPanel( wf=1 ) else: fpanel = 'modelPanel4' return fpanel
def main(): panel = cmds.getPanel(withFocus=True) if cmds.getPanel(typeOf=panel) == 'modelPanel': toggleState = cmds.modelEditor(panel, query=True, wireframeOnShaded=True) cmds.modelEditor(panel, edit=True, wireframeOnShaded=(not toggleState))
def activePanel(): fpanel = mc.getPanel(wf=1) panelType = mc.getPanel(to=fpanel) if panelType == "modelPanel": fpanel = mc.getPanel(wf=1) else: fpanel = "modelPanel4" return fpanel
def batch_playblast(path, pattern): ''' ''' for filePath in glob.glob('{0}/*.m[ab]'.format(path)): #- open file if re.search('\.ma$', filePath): f_type = 'mayaAscii' elif re.search('\.mb$', filePath): f_type = 'mayaBinary' else: continue mc.file(filePath, typ=f_type, o=True, f=True, prompt=False, ignoreVersion=True) #- checking lost reference files unload_refs = [ ref for ref in mc.file(q=True, r=True) if not mc.referenceQuery(ref, il=True) ] lost_refs = [ ref for ref in unload_refs if not os.path.isfile(ref.split('{')[0]) ] if lost_refs: continue #- checking cameras cameras = [ cam for cam in mc.listRelatives(mc.ls(cameras=True), p=True) or list() ] cameras = [cam for cam in cameras if fnmatch.fnmatchcase(cam, pattern)] cameras.append('persp') #- set panels panels = mc.getPanel(vis=True) for pan in panels: if pan in mc.getPanel(typ='modelPanel'): mc.modelEditor(pan, e=True, alo=False) mc.modelEditor(pan, e=True, cam=cameras[0], pm=True, av=True, da='smoothShaded') break #- blast vide_name = '{0}.mov'.format(os.path.splitext(filePath)[0]) playblast(vide_name, view=False) return True
def turnOffCreateNewSetField(self): if not cmds.columnLayout(self.createNewSetLayout, query=True, visible=True): return cmds.iconTextButton (self.plusBtn, edit=True, visible=True, w=25) cmds.columnLayout(self.createNewSetLayout, edit=True, visible=False, w=1) viewports = [view for view in cmds.getPanel(type='modelPanel') if view in cmds.getPanel(visiblePanels=True)] if len(viewports) > 0: cmds.setFocus(viewports[0]) self.adjustButtonsWidth()
def isolate( node ): """isolate node""" nod = mn.Node( node ) nod() currPanel = mc.getPanel( withFocus = True ); panelType = mc.getPanel( to = currPanel ) if panelType == 'modelPanel': mc.isolateSelect( currPanel, state = 1 ) mm.eval( 'enableIsolateSelect %s 1;'%currPanel )
def get_current_camera(self): current_panel = cmds.getPanel(withFocus=True) if current_panel != "": panel_type = cmds.getPanel(typeOf=current_panel) if panel_type == "modelPanel": current_camera = cmds.modelPanel(current_panel, query=True, camera=True) return current_camera
def toggleGeo(): pnl = cmds.getPanel(withFocus=True) if cmds.getPanel(to=pnl) == 'modelPanel': state = cmds.modelEditor(pnl, q=True, polymeshes=True) if state: cmds.modelEditor(pnl, e=True, polymeshes=0) # cmds.modelEditor(pnl, e=True, nurbsSurfaces=0) else: cmds.modelEditor(pnl, e=True, polymeshes=1)
def isolate(node): """isolate node""" nod = mn.Node(node) nod() currPanel = mc.getPanel(withFocus=True) panelType = mc.getPanel(to=currPanel) if panelType == 'modelPanel': mc.isolateSelect(currPanel, state=1) mm.eval('enableIsolateSelect %s 1;' % currPanel)
def getCurrentCamera(self): pan = mc.getPanel(wf=1) cam = "" if ( "modelPanel" == mc.getPanel(to=pan) ): cam = mc.modelEditor(pan,q=1,camera=1); print mc.nodeType(cam) if(cam == ""): return None return mn.Node( cam );
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
def getCurrentPanel(): panel = mc.getPanel(withFocus=True) if mc.getPanel(typeOf=panel) != 'modelPanel': for p in mc.getPanel(visiblePanels=True): if mc.getPanel(typeOf=p) == 'modelPanel': panel = p break return panel if mc.getPanel(typeOf=panel) == 'modelPanel' else None
def _openOutliner(): outliners = cmds.getPanel(typ='outlinerPanel') panl = str(outliners[0]) if _isobjectInList(cmds.getPanel(vis=1), 'outliner'): cmds.evalDeferred("import maya.cmds as cmds;cmds.outlinerEditor('%s', e=1, sc=1);" % panl) else: cmds.OutlinerWindow() cmds.evalDeferred("import maya.cmds as cmds; cmds.outlinerEditor('%s', e=1, sc=1);" % panl) cmds.evalDeferred("cmds.outlinerEditor('%s', e=1, sc=1);" % panl)
def toggle_viewport_nurbs_curves(): panel = cmds.getPanel(withFocus=True) if panel is not None: panelType = cmds.getPanel(typeOf=panel) # panel is model panel if panelType == "modelPanel" and panel: nc = not cmds.modelEditor(panel, q=True, nc=True) cmds.modelEditor(panel, e=True, nurbsCurves=nc)
def getScreenshot(self): #takes a screenshot of the current viewport if self.tempFile is None: filename = str(uuid.uuid4()) self.tempFile = tempfile.gettempdir()+os.sep+filename+".png" cam = cmds.optionMenuGrp("frw_camera",q=True,value=True) #if not cam == "": # cmds.lookThru(cam) panel = cmds.getPanel( withFocus=True ) camera = "" if "modelPanel" == cmds.getPanel(typeOf=panel): camera = cmds.modelEditor(panel, q=True, camera=True)#`modelEditor -q -camera $panel`; else: return "screenshot" filmGate = cmds.camera(camera, q=True, displayFilmGate=True) resolutionGate = cmds.camera(camera, q=True, displayResolution=True) cmds.camera(camera,e=True, displayFilmGate=False) cmds.camera(camera,e=True, displayResolution=False) format = cmds.getAttr("defaultRenderGlobals.imageFormat") cmds.setAttr("defaultRenderGlobals.imageFormat", 32) modelWidth = cmds.layout(panel, q = True, width=True) modelHeight = cmds.layout(panel, q = True, height=True) renderWidth = cmds.getAttr("defaultResolution.width") renderHeight = cmds.getAttr("defaultResolution.height") if renderWidth < modelWidth and renderHeight<modelHeight: self.usingWidth = renderWidth self.usingHeight = renderHeight else: renderRatio = renderWidth/(renderHeight+0.0) widthRatio = renderWidth/(modelWidth+0.0) heightRatio = renderHeight/(modelHeight+0.0) if widthRatio<=1 and heightRatio<=1: usingWidth = renderWidth usingHeight = renderHeight elif widthRatio > heightRatio: self.usingWidth = int(modelWidth) self.usingHeight = int(modelWidth/renderRatio) else: self.usingWidth = int(modelHeight*renderRatio) self.usingHeight = int(modelHeight) time = cmds.currentTime( query=True ) cmds.playblast(frame=time, format="image",cf=self.tempFile, v =0,orn=0,w=self.usingWidth, h=self.usingHeight, p = 100) cmds.setAttr("defaultRenderGlobals.imageFormat",format) cmds.camera(camera, e=True, displayFilmGate=filmGate) cmds.camera(camera, e=True, displayResolution=resolutionGate) return "screenshot="+self.tempFile
def getActiveModelPanel(): """ Get the active model editor panel Returns: modelPanel name (str) """ activePanel = cmds.getPanel(wf=True) if cmds.getPanel(typeOf=activePanel) == 'modelPanel': return activePanel else: return cmds.playblast(ae=True)
def getCurrentCamera(): panel = mc.getPanel(withFocus=True) if mc.getPanel(typeOf=panel) != 'modelPanel': for p in mc.getPanel(visiblePanels=True): if mc.getPanel(typeOf=p) == 'modelPanel': panel = p break return mc.modelEditor(panel, query=True, camera=True) if mc.getPanel( typeOf=panel) == 'modelPanel' else None
def setGates(self, vals): panel = cmds.getPanel( withFocus=True ) camera = "" if "modelPanel" == cmds.getPanel(typeOf=panel): camera = cmds.modelEditor(panel, q=True, camera=True)#`modelEditor -q -camera $panel`; filmGate = cmds.camera(camera, q=True, displayFilmGate=True) resolutionGate = cmds.camera(camera, q=True, displayResolution=True) cmds.camera(camera,e=True, displayFilmGate=vals[0]) cmds.camera(camera,e=True, displayResolution=vals[1]) return [filmGate,resolutionGate]
def show(cls, menu_type, menu_name, preferences, **kwargs): """create marking menu""" cls.hide(kwargs["b"]) if not menu_name: return if menu_type == cls.MEL: cls._mel(menu_name, p=cmds.layout(cmds.getPanel(up=True), q=True, p=True), aob=True, mm=True, **kwargs) elif menu_type == cls.PYTHON: cls._python(menu_name, p=cmds.layout(cmds.getPanel(up=True), q=True, p=True), aob=True, mm=True, **kwargs) else: cls._preset(menu_name, preferences, p=cmds.layout(cmds.getPanel(up=True), q=True, p=True), aob=True, mm=True, **kwargs)
def get_model(): """ This function returns the currently active modelPanel @return str """ currPanel = cmds.getPanel(withFocus = 1) panelType = cmds.getPanel(to = currPanel) if (panelType == "modelPanel"): return currPanel else : OpenMaya.MGlobal.displayWarning("Could not find an active \ viewport, plase select one and re-run")
def getActiveViewport(silent = True): viewport = mc.getPanel(wf = True) if not viewport: msgWin('Error', 'Couldn\'t get active viewport', silent) return False if not viewport.startswith('modelPanel'): try: viewport = [x for x in mc.getPanel(vis=True) if x.startswith('modelPanel')][0] except: msgWin('Error', 'Couldn\'t get active viewport', silent) return False return viewport
def getPanel(): ''' Get current model panel with focus ''' # Get Panel with Focus panel = mc.getPanel(wf=True) # Check Model Panel if not mc.modelPanel(panel,q=True,ex=True): panel = mc.getPanel(type='modelPanel')[0] # Return Result return panel
def getPanel(): """ Get current model panel with focus """ # Get Panel with Focus panel = cmds.getPanel(wf=True) # Check Model Panel if not cmds.modelPanel(panel, q=True, ex=True): panel = cmds.getPanel(type='modelPanel')[0] # Return Result return panel
def _getCam_centerOfInterest(): ## Get camera from current view currentPanel = cmds.getPanel(withFocus= True) or 'modelPanel4' ## Only works with view port active, else create at default world 0, 0, 0 panelType = cmds.getPanel(typeOf = currentPanel) if panelType != "modelPanel": return [0, 0, 0] else: camera = cmds.modelPanel(currentPanel, query = True, camera = True) cameraShape = cmds.listRelatives(camera) or camera position = cmds.camera(cameraShape, query = True, worldCenterOfInterest = True) return [ position[0], 0, position[2] ]
def check_camera_name(): """Get the active panel's camera. Return its status compared to stockCamNames.""" activepanel = cmds.getPanel(withFocus=True) if cmds.getPanel(typeOf=activepanel) == 'modelPanel': cam = cmds.modelEditor(activepanel, query=True, camera=True) if cam in stockCamNames: return True else: return False else: return None
def toggleGrid(): panel = mc.getPanel(withFocus=True) ptype = mc.getPanel(typeOf=panel) # if in UV Editor toggle the according grid there if ptype == 'scriptedPanel' and panel.startswith('polyTexturePlacementPanel'): state = mc.textureWindow(panel, q=True, tgl=True) mc.textureWindow(panel, e=True, tgl=not state) # else use these 2 grid toggelling methods to switch it for sure elif ptype == 'modelPanel': state = True if mc.grid(q=True, toggle=True) or mc.modelEditor(panel, q=True, grid=True): state = False mc.grid(toggle=state) mc.modelEditor(panel, e=True, grid=state)