Python类型错误:检索默认参数时出错

时间:2013-11-13 13:29:51

标签: python arguments default typeerror maya

我现在正在使用Python以特定方式在maya上创建和控制粒子。目前我正在玩我制作的两个函数,其中一个函数出现了这个错误:

错误:

TypeError: Error retrieving default arguments

这是我的函数代码:

# The purpose of this function is to make a magnetic effect to my particles, which are following
# a locator as a goal, so when particle is closer to this locator, the strenght with it moves
# towards the locator will be stronger and when it is far from the locator it will be weaker

# ind= will be the number of the particle/locator, for example: "locator1" = "locator"+str(ind)
# lastF= is the number of Frames we want this to be applied
# interval= for loop management, do this each "interval" frames'''
def magneticCheck(ind= 0, lastF= 10, interval= 10):
    # I was using a for loop before, but I tried a while loop just in case it fixes this issue, it doesn't
    i= 1
    while i < lastF:
        cmds.currentTime(i)
        # Getting Locator's position
        posL = cmds.getAttr( 'locator'+str(ind)+'.translate')
        # Getting Particle's position
        posP = cmds.getAttr( 'nParticle'+str(ind)+'.translate')

        # Calculating distance between Locator and Particle
        distance = math.sqrt((posP[0][0] - posL[0][0])**2 
                              + (posP[0][1] - posL[0][1])**2 
                              + (posP[0][2] - posL[0][2])**2)
        distance = distance/10  # This is just for having smaler values

        # Setting a proper goal strenght for Particle following Locator
        weight = 0
        if distance != 0:
            weight = (1/distance) * 0.5
        else:
            weight = 0.5
        # Applying the goal strenght/weight
        cmds.setAttr( 'nParticleShape'+str(ind)+'.goalWeight[0]' , weight )
        # Setting a new Keyframe at this point
        cmds.setKeyframe()
        i+= interval

# Now loop will go each "interval" frames and will check distance between particle and locator

# This works fine, creates a particle and locator at point (0, 10, 0)
newParticle( 0, 10, 0)

# Using the function ,which compiles fine, makes the error
magneticCheck(ind= 1,lastF= 400,interval= 10)

回溯(为此我将插入newParticle函数如何工作,它尚未引用 但它最重要的是最终代码行,在return语句中)

def newParticle( x, y, z):
    locator= cmds.spaceLocator()
    cmds.move( x, y, z, locator)

    part=    cmds.nParticle( p=( x, y, z ))

    cmds.goal( part , g= locator , w= 0.5)

    return [ part , locator ]

所以我通过这种方式创建了像result= newParticle(x,y,z)这样的新粒子和定位器,在此之后我只需要将它们分配到两个数组中,以便将所有内容组织起来:

locator[0]= result[1]
particles[0]= result[0]

然后我尝试使用magneticCheck这样:

magneticCheck( particles[0], locator[0], lastF, interval)

这样,当我setAttrgetAttr时,我只需要:

cmds.getAttr( locator[0]+'.translate' )

它无效,因为它总是返回错误object '1' does not exist,所以它没有正确使用locator[0],甚至更改它仍然有问题。

在此之后,我提出了连接名称"locator"+ str(i) + ".translate"的想法,因为每次创建粒子或定位器时,它都会自动收到名称"locator1""locator2"等。所以这是有效的,也更容易理解。

然后我发现这个default argument错误,在它是ERROR: Default argument follow but non-default argument之前,所以我只需要交换我在函数上放置参数的方式,修复它,但后来我找到了新的ERROR: Type Error: error retrieving default arguments然后卡住了。

这是我第一次收到此错误,所以我不知道如何处理它。

0 个答案:

没有答案