TypeError:' module'对象不可调用#

时间:2016-04-08 04:08:47

标签: python

我到达了一个球体的位置,然后我得到了那个错误。我不知道该怎么做。这段代码的重点是使滑块工作

import maya.cmds as cmds
from functools import partial
import os
import random as rand

class gridTestUI():
    def __init__(self, winName="gridTest"):
        #Attributes of the class
        self.winTitle = "create a window with a grid layout"
        #This is the name of the window
        self.winName = winName
        self.numSpheres = 3
        self.getSpheres = []
        self.makeSpheres()
        self.createUI()
        self.movePlacement = []#my change
    def createUI(self):
        #Test to see if the window exists
        if cmds.window(self.winName, exists=True):
            #delete the window
            cmds.deleteUI(self.winName)
        #create a new window
        cmds.window(self.winName, title=self.winTitle)

        cmds.scrollLayout( 'scrollLayout' )
        cmds.columnLayout( adjustableColumn=True )
        cmds.frameLayout( label='Buttons', borderStyle='in' )
        self.mainGrid = cmds.gridLayout( numberOfColumns=self.numSpheres, cellWidthHeight=(200, 200) )        
        for sphereName in self.getSpheres:
            cmds.button(l=sphereName,command=partial(self.selectSphere, sphereName))
        #This command allow you to create a button
        cmds.setParent( '..' )
        cmds.setParent( '..' )
        cmds.frameLayout( label='Sliders', borderStyle='etchedIn' )
        cmds.columnLayout()
        self.moveSlider = cmds.floatSliderGrp( label='Move Sphere', field=True, minValue=-10.0, maxValue=10.0, value=0 )
        cmds.setParent( '..' )
        cmds.setParent( '..' )
        cmds.showWindow( self.winName )
        #cmds.window(self.winName, edit=True, widthHeight=[450,300])


    def selectSphere(self,args=None,arg=None):
        cmds.select(args)

    def makeSpheres(self):
            for j in range(self.numSpheres):
                self.movePlacement = [0,2,3,6,8,10,12,14,16]
                self.getSpheres.append(cmds.polySphere()[0] 
                cmds.move(movePlacement[j],rand(0,9)*moveSlider,movePlacement[j])
    myGrid = gridTestUI()

我认为错误正在这里出现。 Maya似乎很好地完成了剩下的代码。

1 个答案:

答案 0 :(得分:0)

仔细查看您发布的错误消息:

# Error: 'module' object is not callable
# Traceback (most recent call last): 
# File "<maya console>", line 60, in <module> 
# File "<maya console>", line 19, in init 
# File "<maya console>", line 57, in makeSpheres 
# TypeError: 'module' object is not callable

错误位于makeSpheres,请查看该方法:

def makeSpheres(self):
    for j in range(self.numSpheres):
        self.movePlacement = [0,2,3,6,8,10,12,14,16]
        self.getSpheres.append(cmds.polySphere()[0] 
        cmds.move(movePlacement[j], rand(0, 9) * moveSlider, movePlacement[j])

它是:rand(0, 9)rand是您导入random模块的方式,正如错误消息所述,该模块不可调用。您想要调用的是random模块的randint方法。

将方法更改为:

def makeSpheres(self):
    for j in range(self.numSpheres):
        self.movePlacement = [0,2,3,6,8,10,12,14,16]
        self.getSpheres.append(cmds.polySphere()[0] 
        cmds.move(
            movePlacement[j],
            rand.randint(0, 9) * moveSlider,
            movePlacement[j])

事情应该有效(或者如果你的代码存在不同的问题,你应该得到一个不同的错误。)