你好,我习惯于创建一个有多个函数的类每个函数我需要创建自己的公共成员,所以我这样做了,但它给了我一个错误
import maya.cmds as cmds
class creatingShadingNode():
def _FileTexture( self, name = 'new' , path = '' , place2dT = None ):
# craeting file texture
mapping = [
['coverage', 'coverage'],
['translateFrame', 'translateFrame'],
['rotateFrame', 'rotateFrame'],
['mirrorU', 'mirrorU'],
['mirrorV', 'mirrorV']
]
file = cmds.shadingNode ( 'file' , asTexture = 1 , isColorManaged = 1 , n = name + '_file' )
if not place2dT:
place2dT = cmds.shadingNode ( 'place2dTexture' , asUtility = 1 , n = name + '_p2d' )
for con in mapping:
cmds.connectAttr( place2dT + '.' + con[0] , file + '.' + con[1] , f = 1 )
if path:
cmds.setAttr( file + '.fileTextureName' , path, type = 'string' )
self.File = file
self.P2d = place2dT
test = creatingShadingNode()._FileTexture(name = 'test' , path = 'test\test' )
print test.File
我得到第1行:“NoneType”对象没有属性“File”
两件事:
首先,您没有从
_FileTexture()
返回任何内容,而是创建了一个实例并调用了它的方法而没有返回。如果要设置所需的实例成员第二,您没有以常见的Python方式创建类。大多数人会这样做:
大多数差异是表面的,但是如果使用Python约定,您将有一个更轻松的时间。从
object
继承给您一个bunch of useful abilities,最好在__init__
中声明您的实例变量,如果没有其他东西可以让您清楚地知道类可能包含什么。你知道吗相关问题 更多 >
编程相关推荐