【问题标题】:function only using one return for argument仅使用一个返回作为参数的函数
【发布时间】:2019-07-30 18:33:07
【问题描述】:

我的 combine 函数似乎只使用了我想用作参数的三个返回值中的一个。我收到以下错误消息

错误:combine_lists() 只需要 3 个参数(给定 1 个)

我该如何解决这个问题?

删除对 ikw 和 ikpv 的引用使我不会收到错误消息。它认为我可以以这种方式使用来自不同函数的多个返回,但也许不是?

我的按钮代码:

cmds.button(label='IK 2 FK',  command = combine_lists, width=100)

def select_joints_afk():
    Fks = []
    del Fks[:] 
    if cmds.ls(selection = True,type=("transform",'nurbsCurve')):
        sel = cmds.ls(sl=True)
        fkCtrls = cmds.listRelatives(sel, allDescendents=True, type=("transform",'nurbsCurve'))
        Fks = [nurbsCurve for nurbsCurve in fkCtrls if nurbsCurve.startswith('FK') & nurbsCurve.endswith('Ctrl')]
        cmds.textFieldButtonGrp(gtF0, edit = True, tx ='' .join(sel),buttonLabel='IK OK',backgroundColor = (.5,.8,.2))
        del Fks[1]
        del Fks[2]
        Fks.extend(sel)

        print Fks[0]
        print Fks[1]
        print Fks[2]
        return Fks 
    else:
        text = cmds.confirmDialog( title='Error', message='Must select joint', button=['OK'], defaultButton='Ok', dismissString='No' )


def select_joints_aikw():
    ikw = []
    del ikw[:]
    if cmds.ls(selection = True,type=("transform",'nurbsCurve')):
        ikwrist=cmds.ls(selection = True)
        ikw = [nurbsCurve for nurbsCurve in ikwrist if nurbsCurve.startswith('IK') & nurbsCurve.endswith('Ctrl')]
        cmds.textFieldButtonGrp(gtF1, edit = True, tx ='' .join(ikwrist),buttonLabel='IK OK',backgroundColor = (.5,.8,.2))
        print ikw
        return ikw
    else:
        text = cmds.confirmDialog( title='Error', message='Must select joint', button=['OK'], defaultButton='Ok', dismissString='No' )

def select_joints_ikpv():
    ikpv = []
    del ikpv[:]
    if cmds.ls(selection = True,type=("transform",'nurbsCurve')):
        ikPvsel = cmds.ls(selection = True)
        ikpv = [nurbsCurve for nurbsCurve in ikPvsel if nurbsCurve.startswith('IK') & nurbsCurve.endswith('Ctrl')]
        cmds.textFieldButtonGrp(gtF2, edit = True, tx ='' .join(ikPvsel),buttonLabel='IK OK',backgroundColor = (.5,.8,.2))        
        print ikpv
        return ikpv
    else:
        text = cmds.confirmDialog( title='Error', message='Must select joint', button=['OK'], defaultButton='Ok', dismissString='No' )

def combine_lists(Fks,ikw,ikpv):


    Fks =  select_joints_afk()

    ikw = select_joints_aikw()

    ikpv = select_joints_ikpv()


    print Fks+ikw+ikpv

【问题讨论】:

  • 你调用这个函数的代码在哪里?
  • 欢迎来到 StackOverflow。请按照您创建此帐户时的建议阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布 MCVE 代码并准确说明问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您指定的问题。你的代码从不调用combine_lists,所以我看不出你怎么会得到这个错误。此外,还发布了 很多 额外代码。
  • 对此感到抱歉。我现在才加的

标签: python function arguments maya


【解决方案1】:

你有

def combine_lists(Fks,ikw,ikpv)

这意味着每当您调用 combine_lists() 时,您都需要向它传递三个参数……即 combine_lists(x, y, z)。看起来您只是在使用 combine_lists 来计算这三件事,而您并没有尝试传递任何东西.. 所以就这样做:

def combine_lists():


   Fks =  select_joints_afk()

   ikw = select_joints_aikw()

   ikpv = select_joints_ikpv()


   print Fks+ikw+ikpv

【讨论】:

    【解决方案2】:

    将对 combine_lists 的调用封装到 functools.partial

    arg1 = 1
    arg2 = 2
    arg3 = 3
    tfunc = functools.partial(combine_lists, arg1, arg2, arg3)
    cmds.button(label='IK 2 FK',  command=tfunc, width=100)
    

    另外,我认为您可以在这里使用 lambda,但我现在无法对其进行测试,因此无法确定。

    【讨论】:

      猜你喜欢
      • 2020-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2018-11-09
      • 2021-03-29
      相关资源
      最近更新 更多