Trouble with pm.deleteUI method in a basic window class


#1

Hey Guys, having a little trouble getting the pm.deleteUI( self, window=True ) method to work. I have created a basic window class. So I can create the instance and show it but when I call the DeleteMyWindow method I an error that Maya cannot find the instance. However if I print test I get the instance. Any thoughts?


#2

Your delete method is trying to delete the class instance. It should be pm.deleteUI(self.window)

Also – don’t forget to derive from object in Python 2.7 classes:

 class TestWin(object):
       #etc

#3

Thanks for the help Theodox, I got it :slight_smile:
I tried pm.deleteUI(self.window) and I got the same error however when I tried setting up the method this way it worked.

def DeleteMyWindow(self):
pm.deleteUI( window)

I am new to setting up classes and transitioning over to Pymel and I am not sure what you mean by " Also – don’t forget to derive from object in Python 2.7 classes:" Did I do something wrong setting up this Class?

Thanks


#4

So instead of doing self = pm.window(), try self.window = pm.window(), and try that same pattern for the other elements you’re creating.

Basically by saying self = you’re just overriding the local name of self whereas self.some_name = is setting an attribute on the instance, which you can refer to in other methods, by doing self.some_name.