Skip to content

Instantly share code, notes, and snippets.

View patwooky's full-sized avatar

Patrick Woo patwooky

View GitHub Profile
@patwooky
patwooky / maya_makeRandomHierarchy_v01.py
Created August 9, 2017 17:34
Creates a hierarchy of with configurable depth, and random number of objects in Maya
'''
makeRandomHierarchy
by Patrick Woo
v001_01
20170809
Creates a hierarchy of with configurable depth, and random number of objects in Maya
'''
from pymel.core import *
@patwooky
patwooky / 20170731_hideDeselectedNodeType_v01.py
Last active August 3, 2017 04:20
Maya Python script. Hides the transform nodes of types that are not selected
import maya.cmds as mc
def hideDeselectedNodeType(targetNodeType):
# selectedNodeTransforms will contain transform nodes
# of all target node type shapes that are selected
selectedNodeTransforms = []
for selNode in mc.ls(sl=True):
if targetNodeType in mc.nodeType(selNode):
# selected node is the correct type
# add the transform node to selectedNodeTransforms
selectedNodeTransforms.append(mc.listRelatives(selNode, parent=True))
import maya.cmds as mc
import random, string
from functools import partial
def randomButtonTest():
buttonsList = []
numButtons = 5
winName = 'randomButtonWin'
winWidth = 250
statusTfgName = 'myStatusTfg'
@patwooky
patwooky / selfScaleXConstraintToYZ.py
Created July 17, 2017 02:51
Maya Python script. Toggle an object's scale constraint x to y, z. constraint an object's scaleX to its own scaleY and scaleZ. if it's already constrained, break it
# Maya Python Script
# toggle scale constraint x to y, z
# constraint an object's scaleX to its own scaleY and scaleZ.
# if it's already constrained, break it
from pymel.core import *
sel = ls(sl=True)[0]
if sel.sy.isConnected() and sel.sz.isConnected(): sel.sy.disconnect(); sel.sz.disconnect();
else: sel.sx >> sel.sy; sel.sx >> sel.sz
class book(object):
classCount = 0
def __init__(self, name='no name', numPages=0):
self.numPages = numPages
self.bookName = str(name)
book.classCount += 1
def getNumPages(self):
return self.numPages
@patwooky
patwooky / mayaCmdsVsPymel.py
Last active April 25, 2017 03:25
a function to compare a time taken to perform similar set of actions using maya.cmds and pymel.
'''
a function to compare a time taken to perform similar
set of actions using maya.cmds and pymel.
original code taken from:
http://www.macaronikazoo.com/?p=271
'''
import time
import maya.cmds as mc
@patwooky
patwooky / 20170123_pymel_enableDisableFileTextures.py
Last active January 24, 2017 04:13
Deactivate and activate all file texture nodes in Maya
from pymel.core import *
import os
'''
Written by Patrick Woo
Sometimes when Maya has an active connection to the texture files, they become locked and
the user cannot save over the filenames to update their contents.
In such a case the user can only unlock the file when the Maya session closes. This is quite annoying and ineffcient.
@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)
@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
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)):