Posts

Showing posts from April, 2017

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]