如何使用参数?

2024-06-25 23:25:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试选择多个曲线CV

这是我的函数代码

这是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()

如何使用参数?你知道吗


Tags: 函数trueifdefmcselectcvlabel
1条回答
网友
1楼 · 发布于 2024-06-25 23:25:41

首先不要使用“len”来存储变量。这是一个非常有用的python函数。。。。 这里有一个方法。你需要把select函数放在循环之外 您可以使用-add标志,但它可能非常慢 将第一个CV存储到变量中: (我星期一才有玛雅,但我希望这会有帮助)

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)

相关问题 更多 >