作为更多有关Python的一部分,我试图在Maya中创建一个复制工具。我设法通过脚本来做到这一点,但是我想创建一个可编辑的窗口,该窗口将定义随机生成的种子和可复制对象的数量(在这种情况下,我将其称为盾牌)。但是到目前为止,我得到的唯一是“#错误:语法无效”。谢谢您的帮助或解释,谢谢!
import maya.cmds as cmds
import random
def createUI(pWindowTitle, pApplyCallback):
windowID = 'myWindowID'
if cmds.window( windowID, exists=True):
cmds.deleteUI (windowID)
cmds.window( windowID, title=pWindowTitle, sizeable=True, resizeToFitChildren=True)
cmds.rowColumnLayout (numberOfColumns=3, columnWidth=[ (1,75), (2,60), (3, 60)], columnOffset=[ (1,'right', 3) ] )
cmds.text( label='Random Seed:')
seedNumber = cmds.intField( minValue=0, maxValue=10000, value=0 )
cmds.separator (h=10, style='none')
cmds.text( label='Shield Amount:')
shieldAmount = cmds.intField( minValue=0, maxValue=1000, value=0 )
cmds.separator (h=10, style='none')
cmds.separator (h=10, style='none')
cmds.separator (h=10, style='none')
cmds.separator (h=10, style='none')
cmds.separator (h=10, style='none')
cmds.button( label='Apply', command=functools.partial( pApplyCallback,
seedNumber,
shieldAmount) )
def cancelCallback(*pArgs):
if cmds.window( windowID, exists=True):
cmds.deleteUI (windowID)
cmds.button( label='Cancel', command=cancelCallback)
cmds.showWindow()
def ShieldCreation (pSeedNumber, pShieldAmount)
random.seed (pSeedNumber)
result = cmds.ls( orderedSelection = True)
transformName = result[0]
instanceGroupName = cmds.group( empty=True, name = transformName + '_instance_grp#')
for i in range( 0, pShieldAmount):
instanceResult = cmds.instance( transformName, name = transformName + '_instance#')
cmds.parent ( instanceResult, instanceGroupName )
x = random.uniform(-10, 10)
y = random.uniform(0, 20)
z = random.uniform(-10, 10)
cmds.move( x, y, z, instanceResult)
xRot = random.uniform(0, 360)
yRot = random.uniform(0, 360)
zRot = random.uniform(0, 360)
cmds.rotate( xRot, yRot, zRot, instanceResult)
scalingFactor = random.uniform (0.3, 1.5)
cmds.scale( scalingFactor, scalingFactor, scalingFactor, instanceResult)
cmds.hide (transformName)
cmds.xform( instanceGroupName, centerPivots = True)
result: [u'pCylinder1']
def applyCallback ( pSeedNumber, pShieldAmount, *Args):
seedNumber = cmds.intField( pSeedNumber, query=True, value=True)
shieldAmount = cmds.intField( pShieldAmount, query=True, value=True)
selectionList = cmds.ls( selection = True, type = 'transform' )
createUI( 'My Title', applyCallback)