Skip to content

Instantly share code, notes, and snippets.

View patwooky's full-sized avatar

Patrick Woo patwooky

View GitHub Profile
@patwooky
patwooky / 20161221_folderOperations.py
Last active December 21, 2016 02:26
Common file operations from the Python os module
import os
myPath = r'W:\FROM_TVC'
# list all objects in the directory
[os.path.join(myPath, x) for x in os.listdir(myPath)][:5]
'''
# Result: ['W:\\FROM_TVC\\.DS_Store',
'W:\\FROM_TVC\\._.DS_Store',
'W:\\FROM_TVC\\._9430_Dynamo',
'W:\\FROM_TVC\\._xxxx_Dig_SkyPlus',
'W:\\FROM_TVC\\._9451_Duracell'] #
@patwooky
patwooky / mayaArnoldMeshSubdivTypeChange.py
Last active November 26, 2021 05:05
Maya script to set multiple Arnold shape nodes attributes
from pymel.core import *
def mayaArnoldSubdivSet():
'''
changes the subdivision type of a mesh shape for Arnold rendering in Maya.
Without subdivisions enabled, the mesh will not tessellate further for displacement.
The following takes each selected object and turns the mesh subdiv type into catclark type.
'''
counter = 0
for x in listRelatives(ls(sl=True), ad=True, type='shape'):
x.aiSubdivType.set(1) # set shape node arnold subdivType to 'catclark'
@patwooky
patwooky / duplicatesToInstances_v01_04.py
Last active October 31, 2016 10:25
This Maya tool deletes all shape nodes from the a list of selection, and replaces those shapes with the shape node of the last selected object, turning all objects into instances of the last object
'''
---
Duplicates to Instances
version: v01_04
date: 20161031
Written by: Patrick Woo
[email protected]
---
Description:
@patwooky
patwooky / uniformScaleLock.py
Created October 25, 2016 07:02
Connects scaleX to scaleY and scaleZ, and locks scaleY and scaleZ. run it again on the same object and it will unlock scaleY, scaleZ, and disconnect both the attrs
def uniformScaleLock(sel=ls(sl=True)):
'''
connects scaleX to scaleY and scaleZ, and locks scaleY and scaleZ
run it again and it will unlock scaleY, scaleZ, and disconnect both the attrs
'''
if not sel:
print 'nothing selected. quitting'
return
if type(sel) == type(list()):
sel = sel[0]
@patwooky
patwooky / getAttrCategories_20161024.py
Created October 24, 2016 05:08
Maya attributes can have categories assigned to them. We can implement our own categories in attributes at creation time. This function returns a list of categories present in a Maya object's attributes.
from pymel.core import
def getAttrCategories(obj=None):
'''
Maya attributes can have categories assigned to them
we can implement our own categories in attributes at creation time
this function returns a list of categories present in a Maya object's attributes
'''
if not obj:
print 'getAttrCategories: no objects passed in. aborted'
return
@patwooky
patwooky / createBoundingBoxGeo_v01_01_20161021.py
Last active October 21, 2016 05:33
Creates a bounding box from selection
'''
---
makeBoundingBoxGeo
version: v01_01
date: 2016-10-21
Patrick Woo
[email protected]
---
creates a box from selection's bounding box
'''
@patwooky
patwooky / testSysExitInModule.py
Last active October 21, 2016 05:04
Exiting by sys.exit() in a Module
import sys
print 'moduleTestSysExit running'
print __name__
print 'i am quitting'
# quitting in a module to see if it quit the main running function
# (it actually does quit the main function)
sys.exit('i quit')
@patwooky
patwooky / embedImageInSource_20161019.py
Created October 19, 2016 08:25
Embeds an image in source file
import os
import base64
headerImg = b'''
iVBORw0KGgoAAAANSUhEUgAAAfQAAAB/CAYAAAAZ1jAlAAAACXBIWXMAAAsTAAALEwEAmpwYAAAK
T2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AU
kSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXX
Pues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgAB
eNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAt
AGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3
@patwooky
patwooky / maya_shapesUnderSelection.py
Created October 14, 2016 06:59
Gets the number of shapes in your selection. If a top level is selected, all the child shape nodes are calculated. Multiple selections are allowed.
'''
Gets the number of shapes in your selection. If a top level is selected, all the child shape nodes are calculated.
Multiple selections are allowed.
'''
from pymel.core import *
print '\n--\nselection has %i shape nodes\n--\n' % len(listRelatives(ls(sl=True), ad=True, type='shape'))
@patwooky
patwooky / maya_normalsConstraintTest_v01_001_20161007.py
Last active October 14, 2016 06:59
constraint normals of objects to surface vertices
'''
constraints objects to normal of each vertex
constraints to face normals are exactly the same procedure
'''
from pymel.core import *
def normalsTest(inObj):
sel=inObj
grpName = group(empty=True)
ptsList = inObj.getShape().getPoints(space='world')
loc = spaceLocator()