'how to run multiple defs () - Python MAYA?
I am following a Python for Maya tutorial from: https://github.com/gyassa4/MayaPyth/blob/master/gear_builder.py After I run the code it only run first def() which creates a Gear with teeth=10. However, it won't run the second def() which changes the number of gears' teeth as instructed in def changeTeeth(constructor, extrude, teeth=25, length=1).Do I need a Class to run multiple defs()?
import maya.cmds as cmds
def createGear(teeth=10, length=1):
spans = teeth * 2
transform, constructor = cmds.polyPipe(subdivisionsAxis=spans)
sideFaces = range(spans * 2, spans * 3, 2)
cmds.select(clear=True)
for face in sideFaces:
cmds.select('%s.f[%s]' % (transform, face), add = True)
extrude = cmds.polyExtrudeFacet(localTranslateZ = length)[0]
return transform, constructor, extrude
createGear()
def changeTeeth(constructor, extrude, teeth=25, length=1):
spans = teeth * 3
cmds.polyPipe(constructor, edit=True, subdivisionsAxis=spans)
sideFaces = range(spans * 2, spans * 3, 5)
faceNames = []
for face in sideFaces:
faceName = 'f[%s]' % (face)
faceNames.append(faceName)
cmds.setAttr('%s.inputComponents' % (extrude),
len(faceNames),*faceNames,type="componentList")
cmds.polyExtrudeFacet(contructor, extrude, edit=True, ltz=length)
Solution 1:[1]
createGear()
this is running the first def
changeTeeth(constructor = "objname",
extrude = "extrudename")
put this at the end will run the second one Note that two of the arguments are mandatory as you have assigned default values to :
teeth=25, length=1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DrWeeny |