This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)): |