-1

I'm creating a GUI in Maya that will either make a procedural material or a material with user input texture files. There are a lot of place holders in my code but right now I am trying to get my Create button to print different statements depending on which radio button is clicked. I know how to do this with PyQt5 but I'm still learning Maya GUI.

When I run my current code I get this error:

Error: RuntimeError: file line 87: Object '<main.Custom_Shader_Window object at 0x0000019CBB34E648>' not found.

I tried using the answer to this question to help me but I'm still struggling. for maya how do i call a function within another function Any help/advice would be greatly appreciated. My current code:

class Custom_Shader_Window(object):
        
    #constructor
    def __init__(self):

        self.window = "AR_Window"
        self.win_title = "Custom Shader"
        self.mat_title = "Material"
        self.attr_title = "Attributes"
        self.size = (400, 400)

        # close old window is open
        if cmds.window(self.window, exists = 1):
            cmds.deleteUI(self.window, window = 1)

        #create new window
        self.window = cmds.window(self.window, title = self.win_title, widthHeight = self.size)
        form = cmds.formLayout(numberOfDivisions=100)

        mat_title = cmds.text(self.mat_title)
        attr_title = cmds.text(self.attr_title)

        attrs = cmds.optionMenuGrp(cw = [1,10])
        cmds.menuItem(l = 'aiStandardSurface')
        cmds.menuItem(l = 'aiToon')
        cmds.menuItem(l = 'standardSurface')
        cmds.menuItem(l = 'Lambert')
        cmds.menuItem(l = 'Blinn')
        cmds.menuItem(l = 'Phong')
        cmds.menuItem(l = 'aiFlat')
        cmds.menuItem(parent=(attrs +'|OptionMenu'), label='Blue' )

        attr_list = cmds.textScrollList( numberOfRows=8, allowMultiSelection=True,
                                        append=['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten',
                                                'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen'],
                                        showIndexedItem = 1, w = 170)

        self.radio_butts = cmds.radioButtonGrp(la2 = ['Procedural', 'Texture Files'], nrb = 2, on1 = self.do_procedural,
                                          on2 = self.do_txt_f, an1 = 'Can work on any objects. Will add procedural noise textures that can be customized by the user.',
                                          an2 = 'Only works on objects with the same UVs. User can browse for desired texture files.')

        self.browse_field = cmds.textFieldButtonGrp(it = 'Texture File Here', bl = 'Browse', ann = 'Click "Browse" to search for texture file.', bc = self.do_browse_butt)

        create_butt = cmds.button(l = 'Create', w = 150, command = self.do_butt, aop = 1)

        help_txt = cmds.helpLine()

        cmds.formLayout(form, edit = 1, af = [(mat_title, 'top', 5), (mat_title, 'left', 100), (attr_title, 'top', 5),
                                              (attr_title, 'right', 100), (attrs, 'top', 50), (attrs, 'left', 5),
                                              (attr_list, 'top', 50), (attr_list, 'right', 5), (self.radio_butts, 'top', 150),
                                              (self.radio_butts, 'left', 100), (self.browse_field, 'bottom', 100),
                                              (self.browse_field, 'left', 50), (create_butt, 'bottom', 50),
                                              (create_butt, 'left', 5), (help_txt, 'left', 5), (help_txt, 'bottom', 20)])

        cmds.showWindow(self.window)
        
    def do_procedural(self, *args):
        print('Procedural')
        cmds.disable(self.browse_field)
        
    def do_txt_f(self, *args):
        print('Texture Files')
        cmds.disable(self.browse_field, v = 0)
        
    def do_browse_butt(self, *args):
        basicFilter = "All Files (*.*)"
        img_dir = cmds.fileDialog2(ff = basicFilter, dialogStyle=2, cap = 'test', fm = 1)
        print(img_dir)
        dir_split = img_dir[0].split("/")
        print(dir_split)
        img_file = dir_split[-1]
        print(img_file)
        
    def do_browse_txt(self, *args):
        basicFilter = "All Files (*.*)"
        img_dir = cmds.fileDialog2(ff = basicFilter, dialogStyle=2, cap = 'test', fm = 1, ocm = 'global proc MyCustomOptionsUICommit(test $formLayout)')
        
    def do_butt(test, self, *args):
        print('butt')
        self.radio_butts = cmds.radioButtonGrp(test, q=1, select=1)
        if self.radio_butts == 1:
            print('true')
        elif self.radio_butts == 2:
            print('false')



myWindow = Custom_Shader_Window()

1 Answers1

1

Your button command has the wrong signature: You write

def do_butt(test, self, *args):

What is not correct for a class method, it has to be

def do_butt(self, test, *args):

And your line:

self.radio_butts = cmds.radioButtonGrp(test, q=1, select=1)

does not make sense because test is False and you assign the value of the radio button query to the radio button object and overwrites it. It has to be:

value = cmds.radioButtonGrp(self.radio_butts, q=1, select=1)
haggi krey
  • 1,885
  • 1
  • 7
  • 9