Maya Scripts

# nHair Simulation Playback Optimization

 

nHair > Make Selected Curves Dynamic (this makes follicles default to point lock on both ends which we fix with

the following python script)

But First select collision mesh and create Passive Collider (under nCloth menu)

 

Select all follicles and Run the Python script below. It sets all the Follicle node's Point Lock attribute to Base for locking root of Hair Curves but letting tips be free.

#

import maya.cmds as cmds
def folliclePointLocks():

    sel = cmds.ls(sl=True)        
    follicleShapeNode = cmds.listRelatives(sel, shapes = True)
    for i in range(0, len(sel)):
        try:
            cmds.setAttr(follicleShapeNode[i]+".pointLock", 1)
        except:
            pass
folliclePointLocks()

def connectNucleusToHair():
    cmds.connectAttr('nRigid1.nucleusId', 'hairSystem1.attachObjectId')
    
connectNucleusToHair()


 

# Duplicate objects, center them to origin, and export selected objects to the specified path :

​import maya.cmds as cmds

global selection_02

selected = cmds.ls(sl=True)

 

def duplicate_selected():

    mel.eval('duplicate -rr;')

    selected = cmds.ls(sl=True)

    try:

        mel.eval('parent -w;')

    except:

        pass

    selection_02 = cmds.select(r=True)

 

duplicate_selected()

 

def center_pivot():

    mel.eval('CenterPivot;')

    mel.eval('move -rpr 0 0 0 ;')

    mel.eval('SnapToGrid; dR_enterForSnap;')

 

center_pivot()

if (cmds.window('uiWindow_objLoopExport', q=1, ex=1)):

    cmds.deleteUI('uiWindow_objLoopExport')

if (cmds.windowPref('uiWindow_objLoopExport', q=1, ex=1)):

    cmds.windowPref('uiWindow_objLoopExport', r=1)

 

def startExport(path):

    curentObjectSelection = cmds.ls(sl=1, fl=1)

    filePathStr = cmds.textFieldButtonGrp('Dir', query=True, text=True)

    for item in curentObjectSelection:

        finalExportPath = r"%s/%s.mb" % (filePathStr, item)

        print finalExportPath

        try:

            cmds.select(item)

            mel.eval(

                'file -force -options "groups=0;ptgroups=0;materials=0;smoothing=1;normals=1" -typ "mayaBinary" -pr -es "%s";' % (

                finalExportPath))

            # cmds.file( finalExportPath, preserveReferences = False, type = mayaBinary, exportSelected = True)

            print finalExportPath

        except:

            print "Ignoring object named: '%s'. Export Failed. " % (item)

 

def browseIt():

    path = cmds.fileDialog2(ds=2, fm=2, dir=cmds.workspace(q=True, dir=True), caption='Choose Directory', okc='Set Path')[0]

    cmds.textFieldButtonGrp('Dir', edit=True, text=path)

    return

 

def makeGui():

    uiWindow_objLoopExport = cmds.window('uiWindow_objLoopExport', title="Mass Geo Exporter",

                                         iconName='uiWindow_objLoopExport', widthHeight=(384, 60))

    cmds.columnLayout('uiColWrapper', w=375, adjustableColumn=False, parent='uiWindow_objLoopExport')

    textGrp = cmds.textFieldButtonGrp('Dir', label='Directory Path', cw3=[80, 247, 50], text='(browse for directory)', buttonLabel='browse', buttonCommand=browseIt, parent='uiColWrapper')

    cmds.button('startExport', label="Export Selected", parent='uiColWrapper', width=380, command=startExport)

    cmds.showWindow(uiWindow_objLoopExport)

 

makeGui()

# Snap to selected keyframe in Graph Editor ( Speeds up animation polish pass )

import maya.cmds as cmds

selKey = cmds.keyframe(sl=True, query=True)
cmds.currentTime(selKey[0], edit = True, update = True)


 

# Speed up Material Editing/Hypershade by turning off material thumbnail update (MEL):

renderThumbnailUpdate false;

Nuke Scripts

# Script to create quick grade node masked by a shuffle node :

import nuke
def grade_mask_shuffle():
     sel = nuke.selectedNode()
     nodeWidth = sel.screenWidth()
     if(nodeWidth == 12):
        nodeWidth = 0
     elif(nodeWidth == 80):
        nodeWidth =  34
    
     d = nuke.nodes.Dot()
     d.setXYpos(int(sel['xpos'].getValue()+nodeWidth), int(sel['ypos'].getValue())+50)
     d.setInput(0, sel)

     s = nuke.nodes.Shuffle()
     s.setXYpos(int(d['xpos'].getValue())+75, int(d['ypos'].getValue()-4))
     s.setInput(0, d)

     d1 = nuke.nodes.Dot()
     d1.setXYpos(int(s['xpos'].getValue())+34, int(s['ypos'].getValue())+65)
     d1.setInput(0, s)

     g = nuke.nodes.Grade()
     g.setXYpos(int(d['xpos'].getValue())-34, int(d1['ypos'].getValue())-4)
     g.setInput(1, d1)
     g.setInput(0, d)

     nextNode = sel.dependent()[0]
     nextNode.setInput(0, None)
     nextNode.setInput(0, g)
 
def buildInNode(group):
    with nuke.toNode(group):
        grade_mask_shuffle()    

grade_mask_shuffle()

# Script to Reload all read nodes :

for a in nuke.allNodes('Read'):
    a['reload'].execute()