How do I use arguments?

Asked by At

I'm trying to select multiple curve cvs

these are my function's codes

this is setArg Func:

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

this is execute Func:

 def execute(cvToSel, *args):
    newSel = []
    curves = mc.listRelatives (type = 'nurbsCurve', shapes = True)
    if not curves:
        print ('no curves selected') = 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 ='.cv[%d'%numCv +':%d]'%len, tgl = True)
        elif cvToSel == 'first':
            newSel ='.cv[0' + ':%d]'%cvSelect, tgl = True), replace = True)

this is ui Func:

def ui():
    if mc.window('CV_Select', exists = True):
    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)


How do I use arguments?

1 Answers

DrWeeny On

first dont use 'len' to store a variable. it is a python function really useful.... Here is a way to do it. You need to put your select function outside your loop You could use -add flag but it can be really slow Store first cvs into a variable : (i dont have maya until Monday but I hope it will help)

sel_curves =, dag=1, type='nurbsCurve')
if sel_curves:
    to_sel = []
    cvSelect = mc.intFieldGrp('numberOfCvs', q = True, value1 = True)
    for c in sel_curves:
        cvs ='.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], tgl = True)

--- EDIT ---

Just to answer your comment question :

def execute(CTS,*args):
    cvToSel = setArg(CTS)