def函数:如果没有选择,则返回所有对象的列表 [英] def function : if nothing selected , return a list of all the objects

查看:126
本文介绍了def函数:如果没有选择,则返回所有对象的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图定义一个函数,当我指定一个对象时返回一个列表,并且当我没有指定任何东西时,它返回场景中带有* _control的所有对象的列表。
那是我的函数,但它不工作....
我正在与玛雅然后..

i'm trying define a function that return a list when i specify an object, and it returns a list of all the objects in the scene with *_control when i don't specify anything.. that's my function but it doesn't work.... i'm working with maya then..

from maya import cmds

def correct_value(selection):

       if not isinstance(selection, list):
            selection = [selection]
            objs = selection
            return objs

       if not selection : 
            objs = cmds.ls ('*_control')    
            return objs

当我没有指定任何东西时,它会返回一个错误:

when i don't specify anything it returns an error :


错误:第1行:TypeError:文件第1行:correct_value()
只需要1个参数(0给出)

Error: line 1: TypeError: file line 1: correct_value() takes exactly 1 argument (0 given)

什么是错误的?

推荐答案

def correct_value(selection=None):
     if selection is None:  # note that You should check this before  
                            # You wil check whether it is list or not
        objs = cmds.ls ('*_control')    
        return objs

    if not isinstance(selection, list):
        selection = [selection]
        objs = selection
        return objs

这篇关于def函数:如果没有选择,则返回所有对象的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆