Skip to content

Instantly share code, notes, and snippets.

View patwooky's full-sized avatar

Patrick Woo patwooky

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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'] #
import timeit
from functools import partial
def myEquals(numItems):
xList = [str(x) for x in xrange(numItems)]
# print xList
xCompList = []
for n in xrange(len(xList)):
for o in xrange(n):
for p in xrange(len(xList)):
@patwooky
patwooky / 20161227_pythonEnumerate.py
Created December 27, 2016 04:28
Testing out looping over a list with enumerate in Python
myList = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
for idx, y in enumerate(myList):
print idx, y, myList[idx+1] if idx < len(myList)-1 else y
# output
'''
0 a b
1 b c
2 c d
3 d e
@patwooky
patwooky / 20170123_findTextureFileInMayaScene.py
Created January 23, 2017 05:39
Search all file texture nodes in the scene and return nodes whole filenames contain a search texture file
from pymel.core import *
findTextureStr = 'concreteBrightMask.png' # the name of an image to search file names from
candidateNodesList = [x for x in ls(type='file') if findTextureStr in x.fileTextureName.get()]
print 'texture file found in these file textures:\n{}'.format(candidateNodesList)
select(candidateNodesList, replace=True)