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 + "." + attr;
        if mc.objExists(attribute):
            if mc.getAttr(attribute) != 2:
                mc.setAttr(attribute,2);
                fixtures.append(attribute);
                nodes.append(oC);
    num = len(fixtures);
    if num: msg = "//Result[patch_OCIT]: interpType changed to \"Shortest\" of "+str(num)+" orientConstraint node(s)";
    print msg;
    if selFlg and num: mc.select(nodes);
# COMMAND
_patch_OrientConstraintInterpType(True);

Comments

Popular posts from this blog

HIK: Getting current character and current source.