Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

3/8/18

MAYA - PYTHON - WINDOWS // rename file with replace string

# rename files in directory replace string by another
import os

#r at the beginning of the path so the filename starting with a number sont bien reconnu - raw string literals
renamePath = r"O:\_WORK\PERSO\__SCRIPTS\01_MAYA\_SHELF_custom\shelf_geo_icons"
renamePath = renamePath.replace('\\','/')

# loop and rename
if (renamePath != '') :
    for filename in os.listdir(renamePath):
        if (len(filename.split('.'))==2): # check if file is not a folder (if it contains an extension)
            print filename
            newName = filename.replace("ttt","") # replace
            os.rename(os.path.join(renamePath, filename), os.path.join(renamePath, newName))

6/9/15

NUKE / PYTHON _ copy text from .txt file and paste into the DAG

create a .txt file containing a nuke group or nodes (copy from nuke and paste as a text) then use this function in nuke to create a node from it

import nuke
from PySide import QtGui

def FromTxtToNukeNode():
 with open ("O:/_WORK/.../textfile.txt", "r") as myfile:
  data=myfile.read() #get the text in the .txt file as a string variable
 QtGui.QApplication.clipboard().setText(data) # set to clipboard
 nuke.nodePaste("%clipboard%") # paste into nuke DAG

1/27/15

NUKE / PYTHON _ Toggle heavy node by class


def disableHeavyNodes():
    # Toggle value / 1 disable - 0 enable
    # RSMB / frischluft / sapphire zblur-zdefocus-glow
    global tgl
    try:
        tgl = not tgl
    except NameError:
        tgl = 1 

    nodeArray = ['OFXcom.revisionfx.rsmb3_vectors_v3','OFXcom.revisionfx.rsmb3_v3',
                         'OFXcom.frischluft.openfx.depthoffield_v1','OFXcom.frischluft.openfx.outoffocus_v1',
                         'OFXcom.genarts.sapphire.blursharpen.s_zblur_v1','OFXcom.genarts.sapphire.blursharpen.s_zdefocus_v1','OFXcom.genarts.sapphire.lighting.s_glow_v1']
    for a in nuke.allNodes():
        if a.Class() in nodeArray :
            a['disable'].setValue(tgl)

1/4/15

NUKE / PYTHON _ snippets

nuke.selectedNode().Class()

def reloadReads():
 for myNode in nuke.allNodes("Read") :
  myNode["reload"].execute()
 print "--> Reads reloaded"

11/2/14

NUKE/PYTHON _ toggle fullscreen viewer

def FullscreenViewer():
 m = nuke.menu( 'Viewer' ).findItem( 'Toolbars/Bottom' )
 m.invoke()
 m = nuke.menu( 'Viewer' ).findItem( 'Toolbars/Top' )
 m.invoke()

9/27/14

MAYA/VRAY/PYTHON _ fallof - occlusion shader

create a fallof and occlusion shader for Vray using python
#____________ FALLOF ____________#
def shFallof():
 # gamma node 
 cmds.shadingNode('gammaCorrect',asUtility=True, n='GammaTemp')
 cmds.setAttr('GammaTemp.gammaX', 0.455)
 cmds.setAttr('GammaTemp.gammaY', 0.455)
 cmds.setAttr('GammaTemp.gammaZ', 0.455)

 #Creates Ramp
 cmds.shadingNode('ramp', asTexture=True, n='facingRampTemp')
 # Remove middle color of ramp
 cmds.removeMultiInstance( 'facingRampTemp.colorEntryList[1]', b=True )
 #Modify Ramp
 cmds.setAttr('facingRampTemp.colorEntryList[2].color', 0,0,0, type='double3' )
 cmds.setAttr('facingRampTemp.colorEntryList[0].color', 1,1,1, type='double3' )
 cmds.setAttr('facingRampTemp.colorEntryList[2].position', 1)
 cmds.setAttr('facingRampTemp.interpolation', 1)

 #Creates Sampler Info node
 cmds.shadingNode('samplerInfo', asUtility=True, n='facingSamplerTemp')

 #Connects Ramp and Sampler
 cmds.connectAttr('facingSamplerTemp.facingRatio', 'facingRampTemp.vCoord', f=True)
 cmds.connectAttr('facingRampTemp.outColor', 'GammaTemp.value', f=True)

 # connect it to a surface shader
 cmds.shadingNode('surfaceShader', asShader=True, n='SH_TMP_Fallof')
 cmds.connectAttr('GammaTemp.outValue', 'SH_TMP_Fallof.outColor', f=True)

 # Select Ramp
 cmds.select('facingRampTemp', r=True)

 #Renames nodes so you can use the script as many times as you want
 cmds.rename('facingRampTemp', 'facingRamp_F')
 cmds.rename('facingSamplerTemp', 'facingSampler_F')
 cmds.rename('SH_TMP_Fallof', 'SH_Fallof')
 cmds.rename('GammaTemp', 'gammaCorrect_F') 

shFallof()


#____________ OCCLU ____________#
def shOcclu():
 # surface shader
 cmds.shadingNode('surfaceShader', asShader=True, n='SH_TMP_Occlu')
 cmds.shadingNode('VRayDirt', asShader=True, n='VrayDirt_TMP')
 cmds.connectAttr('VrayDirt_TMP.outColor', 'SH_TMP_Occlu.outColor', f=True)

 #Renames nodes so you can use the script as many times as you want
 cmds.rename('SH_TMP_Occlu', 'SH_Occlu')
 cmds.rename('VrayDirt_TMP', 'VrayDirt_O')

shOcclu()