Posts

MP: Relocate Maya window that has gone off-screen

w= 1000; h= 500; for item in cmds.lsUI(windows=True):     if item=="MayaWindow":         cmds.window(item,e=True,te=10,le=10,wh=[w,h]);

MP: Hypergraph Display

# Hidden Node Display hgphgd= "hyperGraphPanel1HyperGraphEd"; ## Hidden Node display state print( cmds.hyperGraph(hgphgd,q=True,shi=True) ); ## Showing hidden nodes (Hidden Node display on) cmds.hyperGraph(hgphgd,e=True,shi=True); コマンド (Python) hyperGraph

Python: importing all modules from a specified py filepath

thePyFilePath= "D:\\Test.py"; #Python 2.x import imp; allModules= imp.load_source("__all__", thePyFilePath); #Python 3.x from importlib.machinery import SourceFileLoader; SourceFileLoader("__all__",pyFilePath).load_module(); In Maya, both create a pyc file. 2.x creates a pyc file in the same folder as the py file. 3.x creates a pyc file in the __pycache__ folder.

MP: Script path

# list of system path # includes custom path you appended import sys; for path in sys.path:     print(path); # List of script folder path import os; for path in os.environ["MAYA_SCRIPT_PATH"].split(";"):     print(path); # Maya version user script folder path cmds.internalVar(usd=True);

Motionbuilder environment variables

Motionbuilder  environment variables (os.environ) import os; for item in os.environ:     print( item );

Command prompt: Creating a zip file using powershell's compress-archive

Open Command Prompt e.g. enter cmd in search Move to directory where a file you want to zip located using cd command. e.g. cd c:\Users\yourloginname\Documents\ powershell compress-archive before.txt after.zip Result: c:\Users\yourloginname\Documents\after.zip is created.

Merge all animLayers

class animLayerOps: def getNonBaseAnimationLayerNodes(self): ret= []; import maya.cmds as mc; if not self.licCheck(): False; else: import maya.cmds as mc; animLayerNodes= mc.ls(type="animLayer"); for ALN in animLayerNodes: attr= ALN+".parentLayer"; if mc.objExists(attr) and mc.listConnections(attr): ret.append(ALN); return( ret ); def mergeAnimLayers(self): import maya.cmds as mc; bakeAttrs= []; animLayers= self.getNonBaseAnimationLayerNodes(); for item in animLayers: attr= item+".dagSetMembers"; if mc.objExists(attr): cncts= mc.listConnections(attr,p=1,s=1,d=0); if cncts: for item2 in cncts: bakeAttrs.append(item2); bakeAttrs= sorted(set(bakeAttrs),key=bakeAttrs.index); if len(bakeAttrs): start= mc.playbackOptions(q=1,min=1); end= mc.playbackOptions(q=1,max=1); mc.bakeResults(bakeAttrs,t=(start,end),sm=1,mr=1); mc.delete(animLayers);

Getting a BaseAnimation animLayer node.

 def getBaseAnimationLayerNode():     ret= [];     import maya.cmds as mc;     animLayerNodes= mc.ls(type="animLayer");     for ALN in animLayerNodes:         attr= ALN+".parentLayer";         if mc.objExists(attr) and not mc.listConnections(attr):             ret.append(ALN);     return( ret );

Get all referenced nodes in a scene

def getReferencedNodeList():     referencedNodeList= [];     import maya.cmds as mc;     rnodes= mc.ls(type="reference");     for rnode in rnodes:         sharedAttr= rnode+".sharedReference";         if mc.objExists(sharedAttr) and not mc.listConnections(sharedAttr,s=0,d=1):             referencedNodeList+= mc.referenceQuery(rnode,n=True);     return( referencedNodeList );