Posts

Showing posts from 2017

Online Maya Python Command Reference (2018)

Maya Python Command Rerference http://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/CommandsPython/ pymel.core.general https://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/PyMel/generated/pymel.core.general.html

Fix texture file path

Fix texture file path in a scene. When a texture file is selected in the window, it tries to change the directory path of all textures in a scene.  pyc file download URL:  https://goo.gl/x4ptMW Fix texture file path Command import i3d_texture as i3d_txtr; i3d_txtr.fixTextureFilePath(); Usage Execute the command to open a window and locate texture files. pyc i3d_texture.pyc Tips If polygon(s) selected, it tries to find and load textures related to selected polygons.

SmoothBindSkin(MEL) options and skinCluster command flags

MEL command: SmoothBindSkin; Command: skinCluster Bind Skin Options Flags Related Bind to Joint hierarchy toSelectedBones(tsb)=0,toSkeletonAndTransforms(tst)=0   Selected joints toSelectedBones(tsb)=1,toSkeletonAndTransforms(tst)=0   Object hierarchy toSelectedBones(tsb)=0,toSkeletonAndTransforms(tst)=1   Bind method Closest distance bindMethod(bm)=0   Closest in hierarchy bindMethod(bm)=1   Heat map bindMethod(bm)=2 heatmapFalloff(hmf)=0.0-1.0 Geodesic Voxel bindMethod(bm)=3   Skinnning method Classic linear skinMethod(sm)=0   Dual quaternion skinMethod(sm)=1   Weight blended skinMethod(sm)=2   Normalize weights None normalizeWeights(nw)=0   Interactive normalizeWeights(nw)=1 forceNormalizeWeights(fnw)=1 Post normalizeWeights(nw)=2   Weight distribution Distance w...

i3d: Switch constraint targets

It takes over all connected network(attributes) of current target and apply them to new target. pyc file download URL:  https://goo.gl/x4ptMW Switch constraint targets Command import i3d_constraint as i3d_cnst;i3d_cnst.switchConstraintTargetsCMD(); Usage Select constrained node, current target node then new targe node. pyc i3d_constraint.pyc Description https://drive.google.com/open?id=0Bx4LaLJqEkWQUTVrODB3anhQSGM

i3d: animImportExport

Export/Import animations - Maya ASCII file(.ma) Imports all animations(animCurve nodes) to nodes with same name. pyc file download URL:  https://goo.gl/x4ptMW Export animations(animCurve nodes) as a Maya ASCII file(.ma) Command import i3d_importExport as i3d_iept;i3d_iept.animMAExport(); Usage Select a top node of tree(s). pyc i3d_importExport.pyc, i3d_utility.pyc Tips With Shift key pressed, it exports animation curve nodes of selected nodes. (Not tree) Import animations(animCurve nodes) from a saved animation file(.ma) Command import i3d_importExport as i3d_iept;i3d_iept.animMAImport(); Usage Select a top node of tree(s). pyc i3d_importExport.pyc , i3d_utility.pyc Tips With Shift key pressed, it imports to selected nodes. (Not tree) Delete animations(animCurve nodes) of nodes on selected tree Command import i3d_animImportExport as i3d_aIE;i3d_aIE.delAnimCrvOfNodesOnTree(); Usage Select a top node of tree. pyc i3d_animImportExport.pyc

Python: Removing matched items from a list

list1= [12, 50, -20, -120, 14.5, 3, 6, -120]; list2= [3, -200, 50, -120]; list3A= filter(lambda x: x not in list2, list1); #[12, -20, 14.5, 6] list3B= list(set(list1)-set(list2)); #[14.5, -20, 12, 6]

Maya User scripts path (Win/MAC)

def _getMayaScriptFolder(): import os; import platform; dspath=False;f=None;div=":"; spaths=os.environ['MAYA_SCRIPT_PATH']; if platform.system()=="Windows":div=";"; paths=spaths.split(div); for i in range(0,len(paths)): p=paths[i]; brk=p.split("/"); num=len(brk); if num>2 and brk[1]=="Users": for j in range(0,num): if brk[j]=="scripts": if f==None:f=j;spath=p; elif j<f:f=j;spath=p; return(spath); print _getMayaScriptFolder();

animCurve, key values and time

import maya.cmds as mc; ## Querying # Current time crntT = mc.currentTime(q=1); # Getting anim nodes of current key selection animNodesOfSelectedKeys = mc.keyframe(q=1,sl=1,n=1); offsetval= 12.34; if animNodesOfSelectedKeys:      for aNode in animNodesOfSelectedKeys:           # Current time value of selected key curve           keyCurveValue = mc.keyframe(aNode,q=1,ev=1,t=(crntT,crntT))[0];           # Num of keys of an animCurve node           numKeys = mc.keyframe(animCurveNode,q=1,keyframeCount=1);           # All key "TIMES"           times = mc.keyframe(animCurveNode,index=(0,numKeys-1),q=1);           # All key time "VALUES"           vals = mc.keyframe(animCurveNode,t=(times[0],times[len(times)-1]),q=1,valueChange=1);  ...

World position of vtx using MVector

import maya.cmds as mc; from maya.OpenMaya import MVector; verts = mc.filterExpand( poly + ".vtx[*]", sm=31 ); for vtx in verts: pvec = MVector( *mc.pointPosition( vtx ) );

aimConstraint command

def _sample_aimConstraint(): import random; import maya.cmds as mc; sL1 = mc.spaceLocator()[0]; sL2 = mc.spaceLocator()[0]; sL3 = mc.spaceLocator()[0]; mc.xform(sL2,ws=1,t=(random.random()*10,random.random()*10,random.random()*10)); mc.xform(sL3,ws=1,t=(random.random()*10,random.random()*10,random.random()*10)); mc.aimConstraint(sL2,sL1,aim=[1,0,0],u=[0,1,0],wut="object",wuo=sL3);

smoothBinding without any joints.

# this demo binds locator bones only. def _getSkinClusterNode(mesh): import maya.cmds as mc; sC = mc.ls(mc.listHistory(mesh,f=0),type="skinCluster"); if len(sC): sC = sC[0]; else: sC = False; return(sC); def _spaceLocator(pos): import maya.cmds as mc; mc.spaceLocator(); sL = mc.ls(sl=1)[0]; mc.xform(sL,ws=1,t=pos); return(sL); def _demo_addRemoveInf(): import maya.cmds as mc; import maya.mel as mm; mc.select(cl=1); mc.joint(); j1 = mc.ls(sl=1,l=1)[0]; mc.xform(j1,ws=1,t=[1,2,3]); mc.polyCube(w=10,h=10,d=10,sx=1,sy=1,sz=1,ax=[0,1,0],cuv=4,ch=0); poly = mc.ls(sl=1)[0]; mc.select(j1,poly); mm.eval("SmoothBindSkin;"); sLs = []; sLs.append( _spaceLocator([2,3,-4]) ); sLs.append( _spaceLocator([4,2,1]) ); sLs.append( _spaceLocator([-2,-1,-2]) ); sC = _getSkinClusterNode(poly); mc.skinCluster(sC,e=1,ai=sLs); vtx = mc.filterExpand(poly+".vtx[*]...

Speed Test: range() vs enumerate() on Maya

def _speed1(): import maya.cmds as mc; import time; col = []; count = 0; #st = time.time(); sel = mc.ls(sl=1); verts = mc.filterExpand(sel,sm=31); num = len(verts); st = time.time(); for i in range(0,num): for j in range(0,num): col.append(verts[j]); count += (i+1)*(j+1); et = time.time(); print et - st; print "#"+str(st); print "#"+str(et); def _speed2(): import maya.cmds as mc; import time; col = []; count = 0; #st = time.time(); verts = mc.ls(os=1,fl=1); st = time.time(); for i,v1 in enumerate(verts): for j,v2 in enumerate(verts): col.append(v2); count += (i+1)*(j+1); et = time.time(); print et - st; print "#"+str(st); print "#"+str(et); _speed1(); # winner _speed2();

Object's worldMatrix x offset position

def posOffsetMatrix_usingOM(pObj,cObj,tOSVec):     import maya.api.OpenMaya as om;     m1 = om.MMatrix(mc.getAttr(pObj+".worldMatrix"));     m2 = om.MMatrix([1,0,0,0, 0,1,0,0, 0,0,1,0, tOSVec[0],tOSVec[1],tOSVec[2],1]);     mc.xform( cObj, matrix = tuple(m2 * m1) ); def createOffsetLocator(offsets,sl):     import maya.cmds as mc;     locs = [];     sel = mc.ls(sl=1,l=1,o=1);     num = len(sel);     for node in sel:         loc = mc.spaceLocator()[0];         locs.append(loc);         posOffsetMatrix_usingOM(node,loc,offsets);     if num:         if sl: mc.select(sel);         else: mc.select(locs);     return(locs); locs = createOffsetLocator([0,0,10],True);

Python: Current Python file, Current maya file, top nodes, split using os, orientConstraint interpType

import os; import maya.cmds as mc; # getting a location of Python file that is currently executing os.path.dirname(__file__); # Directory path os.path.realpath(__file__); # Py file path # getting current filename fileName = mc.file(q=1,sn=1,shn=1); fileFullpath = mc.file(q=1,sn=1,shn=0); # split by the extention fileName = "theFileName.ma"; spl = os.path.splitext(fileName); #spl = ('theFileName', '.ma'); # Getting top nodes topNodes = mc.ls(assemblies=1,l=1); # Use "Shortest" interp type of orientConstraint to avoid flipping. # INPUT ARGUMENTS: bool # bool: if true, changed orientConstraint nodes will be selected. def _patch_OrientConstraintInterpType(selFlg): #patch_OCIT     msg = "//Result[patch_OCIT]: Nothing changed.";     fixtures = [];     nodes = [];     oCs = mc.ls(type="orientConstraint",l=1);     attr = "interpType";     for oC in oCs:         attribute = oC +...

Accessing to google drive site to get a list of python files.

#Get pyc files saved in Google drive(website) def _getFilesInGoogleDrive():     import re;     import urllib2     pyFiles = [];     # Get page source     #url = 'https://drive.google.com/drive/u/1/folders/0Bx4LaLJqEkWQfmNXQnZtaENlWERxX2o2OHpxOUFyd0FUUTdJcWhyR3FvVVNXTm1sb01iSXc';     url = 'https://goo.gl/hIWbYY';     html = urllib2.urlopen(url).read();     # convert the source to lines     lines = html.split("\n");     # Setups     gUserName = "iron3d exists";     pyStr = ".pyc";     i3dStr = "i3d";     numpy = len(pyStr);     numi3d = len(i3dStr);     for line in lines:         srch = re.search(i3dStr,line);         if srch:             newline = (line.replace("null,","")).replace("\\n","");             spl ...

Maya: Changing display color of nurbsCurves

import maya.cmds as mc; mc.setAttr(shapeNode.overrideEnabled, 1); mc.setAttr(shapeNode.overrideColor, colorValue);

Python: Extract numbers from a string

#Python:  Extract numbers from a string import re; string = "rootNode218|parentNode001|polygonModel.vtx[627]"; list = re.findall(r'\d+',  string ); # ['218', '001', '627'];

Python: Deleting multiple items from a list

#Python: Deleting multiple items from a list a1 = [5,11,1,9]; a2 = [2,5,9,11,18]; a3 = a1 + a2; #[5, 11, 1, 9, 2, 5, 9, 11, 18] a4 = sorted(set(a3), key=a3.index); #[5, 11, 1, 9, 2, 18]