This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | |
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 |
This file contains hidden or 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
''' | |
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. | |
''' |
This file contains hidden or 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 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) |