0

Hello i wont to create a class with multiple function each function i need to create its own public Members so i did this but it gives me an error

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

i get line 1: 'NoneType' object has no attribute 'File'

theodox
  • 12,028
  • 3
  • 23
  • 36

1 Answers1

2

Two things:

First, you're not returning anything from _FileTexture() -- you're creating an instance and calling its method with no return. If the idea is to set instance members you want

instance = creatingShadingNode()
instance._FileTexture(name = 'test' , path = 'test\test' )
print instance.File

Second, you're not creating the class in the common Python manner. Most people would do it like this:

class ShadingNodeCreator(object):
      def __init__(self):
          self.file = None
          self.p2d = None

      def create_file(name, path, p2d):
          # your code here

Most of the difference is cosmetic, but you'll have an easier time if you use the Python conventions. Imheriting from object gives you a bunch of useful abilities, and it's a good idea to declare your instance variables in __init__ -- if nothing else it makes it obvious what the class may contain.

theodox
  • 12,028
  • 3
  • 23
  • 36
  • ok grate so if i wont to create more and more functions each function has to return it`s own members i has to declare all of them in the init function then return each variable i wont in the return of each function like this 'self.File = file self.P2d = place2dT return self.File , self.P2d' – Mahmoud Youssef Jul 23 '17 at 09:24
  • The functions can return anything you want. Use the instance members (self.whatever) for things you want to share between functions – theodox Jul 23 '17 at 17:35