首先,这似乎是学习更多编程知识的好地方。我编写了一个 maya python 脚本,这两个函数都可以工作,但是我无法让 UI 按钮调用 superExtrude() 函数。第一个函数执行几何网格操作,第二个函数应该为用户输入生成 UI:
import maya.cmds as cmds
def superExtrude(extrScale, extrDist):
"""Loops through a list of selected meshes and extrudes all of the mesh faces to produce a polygon frame, based on existing mesh tesselations"""
myObjectLt = cmds.ls(selection=True)
for i in range(len(myObjectLt)):
numFaces = cmds.polyEvaluate(face=True)
item = myObjectLt[i] + ".f[:]"
cmds.select(clear=True)
cmds.select(item, replace=True)
#extrude by scale
cmds.polyExtrudeFacet(constructionHistory=True, keepFacesTogether=False, localScaleX=extrScale, localScaleY=extrScale, localScaleZ=extrScale)
selFaces = cmds.ls(selection=True)
cmds.delete(selFaces)
#extrude by height
cmds.select(item, replace=True)
cmds.polyExtrudeFacet(constructionHistory=True, keepFacesTogether=True, localTranslateZ=extrDist)
def extrWindow():
"""Creates the user interface UI for the user input of the extrusion scale and height"""
windowID = "superExtrWindow"
if cmds.window(windowID, exists=True):
cmds.deleteUI(windowID)
cmds.window(windowID, title="SuperExtrude", sizeable=False, resizeToFitChildren=True)
cmds.rowColumnLayout(numberOfColumns=2, columnWidth=[(1,120),(2,120)], columnOffset=[1,"right",3])
cmds.text(label="Extrusion Scale:")
extrScaleVal = cmds.floatField(text=0.9)
cmds.text(label="Extrusion Height:")
extrDistVal = cmds.floatField(text=-0.3)
cmds.separator(height=10, style="none")
cmds.separator(height=10, style="none")
cmds.separator(height=10, style="none")
cmds.button(label="Apply", command=superExtrude(extrScaleVal, extrDistVal))
cmds.showWindow()
extrWindow()
我对python和maya脚本很陌生,所以任何帮助都将不胜感激。:)