Skip to content

Instantly share code, notes, and snippets.

View patwooky's full-sized avatar

Patrick Woo patwooky

View GitHub Profile
@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 / 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
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 / 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
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 / 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))
@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 / setAssignmentTransfer.py
Last active August 14, 2017 11:18
maya - Transfers ownership of elements in a set from one set to another
import maya.cmds as mc
from pymel.core import *
def setAssignmentTransfer(shaderCurr, shaderNew, module='pymel'):
'''
transfer ownership of elements in a set from one set to another
works on shaders and regular sets
shaderCurr - <objectSet> the current set that holds the collection of objects to be transferred over
shaderNew - <objectSet> the target set which to transfer the objects under
@patwooky
patwooky / respeedKeyframeTimings_v001.py
Created August 22, 2017 05:27
ReSpeed keyframe Timings
'''
Problem:
keyframes from camera tx, ty, tz, rx, ry, rz ranging from 1001 to 1195
need to have their timing remapped, such that the new timing is sped up by 2x
thus, the formula where kT = original frame, is ((kT - 1001) * 0.5) + 1001
This will give us new keyframes from frames 1001 - 1098.
New frame range after re-speed is 1001 - 1093, we just truncate frames 1094 - 1098.
'''
@patwooky
patwooky / iterativeCubesTwist.py
Last active September 9, 2017 17:32
A PyMel script that creates a twisting line of cubes that gradually gets larger
import time
from pymel.core import *
def iterativeFunc(maxNum=20, size=(0.2, 1), rotAngle=(-20, 120)):
for n in range(maxNum):
myCube = polyCube(ch=False)
mySize = [size[0] + ((size[1] - size[0]) /float(maxNum) * n) for x in range(3)]
pos = [(size[1]*1.02) * n, 5, 0]
rot = [(float(rotAngle[1] - rotAngle[0])/maxNum)*n + rotAngle[0], 0, 0]
xform(myCube, t=pos, scale=mySize, rotation=rot)