Difference between revisions of "Maya tmp"
Jump to navigation
Jump to search
Line 28: | Line 28: | ||
cmds.setAttr(obj+'.translateY', random.randint(0, 5)) | cmds.setAttr(obj+'.translateY', random.randint(0, 5)) | ||
cmds.setAttr(obj+'.translateZ', random.randint(0, 5)) | cmds.setAttr(obj+'.translateZ', random.randint(0, 5)) | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | === Maya Python - Randomize translate of selection #2=== | ||
+ | <pre> | ||
+ | #La meme chose en utilisant une fonction | ||
+ | from maya import cmds | ||
+ | import random | ||
+ | |||
+ | objList = cmds.ls(selection=True) | ||
+ | |||
+ | print objList | ||
+ | |||
+ | #On definit la fonction | ||
+ | def randomize(minValue=0, maxValue=5): | ||
+ | for obj in objList: | ||
+ | cmds.setAttr(obj+'.translateX', random.randint(minValue, maxValue)) | ||
+ | cmds.setAttr(obj+'.translateY', random.randint(minValue, maxValue)) | ||
+ | cmds.setAttr(obj+'.translateZ', random.randint(minValue, maxValue)) | ||
+ | |||
+ | #On change si besoin les valeurs par defaut avant d'executer la fonction | ||
+ | randomize(minValue=4, maxValue=20) | ||
</pre> | </pre> |
Revision as of 02:53, 4 November 2019
Contents
Maya tmp Scripts
Maya Python - Create object & Randomize Translate
from maya import cmds import random numObjects = 4 for n in range(numObjects): obj = cmds.polyCube() cmds.setAttr(obj[0]+'.translateX', random.randint(0, 5)) cmds.setAttr(obj[0]+'.translateY', random.randint(0, 5)) cmds.setAttr(obj[0]+'.translateZ', random.randint(0, 5))
Maya Python - Randomize translate of selection #1
from maya import cmds import random objList = cmds.ls(selection=True) print objList for obj in objList: cmds.setAttr(obj+'.translateX', random.randint(0, 5)) cmds.setAttr(obj+'.translateY', random.randint(0, 5)) cmds.setAttr(obj+'.translateZ', random.randint(0, 5))
Maya Python - Randomize translate of selection #2
#La meme chose en utilisant une fonction from maya import cmds import random objList = cmds.ls(selection=True) print objList #On definit la fonction def randomize(minValue=0, maxValue=5): for obj in objList: cmds.setAttr(obj+'.translateX', random.randint(minValue, maxValue)) cmds.setAttr(obj+'.translateY', random.randint(minValue, maxValue)) cmds.setAttr(obj+'.translateZ', random.randint(minValue, maxValue)) #On change si besoin les valeurs par defaut avant d'executer la fonction randomize(minValue=4, maxValue=20)