我正在尝试选择多个曲线cvs
这些是我函数的代码
这是setArg
函数:
import maya.cmds as mc from functools import partial
def setArg(CTS, option, *args):
option = mc.radioButtonGrp(CTS, q=True, select=True)
if option == 1:
cvToSel = 'first'
print cvToSel
elif option == 2:
cvToSel = 'last'
print cvToSel
return cvToSel
这是execute
函数:
def execute(cvToSel, *args):
newSel = []
curves = mc.listRelatives (type = 'nurbsCurve', shapes = True)
if not curves:
print ('no curves selected')
#mc.select(clear = True)
#print curves
for crv in curves:
len = mc.getAttr(crv+'.cp', s=True, multiIndices=True)
cvSelect = mc.intFieldGrp('numberOfCvs', q = True, value1 = True)
numCv = len - cvSelect
if cvToSel == 'last':
newSel = mc.select(crv+'.cv[%d'%numCv +':%d]'%len, tgl = True)
elif cvToSel == 'first':
newSel = mc.select(crv+'.cv[0' + ':%d]'%cvSelect, tgl = True)
#mc.select(newSel, replace = True)
这是ui
函数:
def ui():
if mc.window('CV_Select', exists = True):
mc.deleteUI('CV_Select')
cvWin = mc.window('CV_Select', mxb = False)
mc.columnLayout( adjustableColumn = True )
mc.text( label = 'select curves' )
mc.intFieldGrp( 'numberOfCvs', label = 'Number Of Cvs', value1 = 10 )
ButtonOne = mc.radioButtonGrp( label='Type', labelArray2=['First CVs', 'Last CVs'], numberOfRadioButtons = 2)
mc.button( label = 'Select CVs', command = partial(execute, ButtonOne), align = 'center', aop = True)
mc.showWindow('CV_Select')
ui()
如何使用参数?
答案 0 :(得分:0)
首先不要使用'len'来存储变量。这是一个非常有用的python函数... 这是一种方法。您需要将选择功能放在循环之外 您可以使用-add标志,但是它可能真的很慢 将第一个简历存储到变量中: (我在星期一之前没有玛雅人,但我希望它会有所帮助)
sel_curves = mc.ls(sl=1, dag=1, type='nurbsCurve')
if sel_curves:
to_sel = []
cvSelect = mc.intFieldGrp('numberOfCvs', q = True, value1 = True)
for c in sel_curves:
cvs = mc.ls(c+'.cv[:]', fl=True)
nb_cvs = len(cvs)
if cvSelect > nb_cvs:
nb_cvs = cvSelect
if cvToSel == 'last':
to_sel += cvs[cvSelect:]
elif cvToSel == 'first':
to_sel += cvs[:cvSelect]
cmds.select(to_sel, tgl = True)
---编辑---
只需回答您的评论问题:
def execute(CTS,*args):
cvToSel = setArg(CTS)