我现在正在使用 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)
Traceback(为此,我将插入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)
这样,当我setAttr
和getAttr
我只需要放:
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
并且卡住了。
这是我第一次收到这个错误,所以我不知道如何处理它。