Thanks Justin ! Martin
On Fri, Jul 29, 2011 at 2:56 PM, Justin <[email protected]> wrote: > Some more specific reasons I use classes... > If you want to have it run in a verbose or debug mode, to maybe print > more output, you would make it a class that has say a verbose > attribute. Then all your methods can check "if self.verbose" and do > more output. > Also, say your tool has a UI component to it. I have a lot of tools > that can just be run as a command or can bring up a GUI. You GUI can > be brought up with, say, a show() method and can set the state of > attributes for when the actual work method gets called. > > self.show() -> set some attribs: self.thisVal, self.thatVal -> hitting > an ok button calls self.create() > > I'm sure that I am missing a lot better examples. But I'm just coming > up with this off the cuff :-) > I have one tool that automatically sets up IK on the legs of a > character, from the selected joints. It has a lot of internal state > where its remembers names and paths of objects its creating along the > way. It would be a lot more work for me to have to pass around lots of > data structures to maintain the state as it runs. I can break work up > into smaller routines that maybe don't return anything, but rather > just update the attributes of the class instance. > > Also, if you end up getting into using pyqt in maya (which kicks ass, > as opposed to dealing with that shitty MEL ui code), you will end up > using clases. I wrote a blog article about installing that: > http://www.justinfx.com/2011/01/07/installing-pyqt-for-maya-2011-osx/ > > As for pymel, I tried it out in maya 2009 before it came integrated in > 2011. I like what they were trying to do, by making the calls more > pythonic, but I actually found it to be slower than calling the > standard python API. Probably a lot of overhead in what the underlying > code does to populate its objects. Maybe its faster now, Im not sure. > > > > On Jul 29, 2:55 pm, Martin La Land Romero <[email protected]> > wrote: > > I was also wondering the same thing that pixelmuncher brought up. I > usually > > relay on functions instead of classes. I would love to learn more about > > their within maya. > > > > Thanks > > On Jul 29, 2011 10:20 AM, "PixelMuncher" <[email protected]> wrote: > > > > > > > > > > > > > > > > > Justin pretty much summed it up. > > > I'm not a professional coder, but I write a lot of Maya tools for > > > myself. > > > I started w/Mel, then checked out Python, which has become my favorite > > > language. > > > I haven't used classes, and want to find out about what I'm missing. > > > I understand your point of view Alexander - that using classes could > > > be considered superfluous for my needs, but I want to see how they > > > work and if I can see any advantage to using them in my coding. > > > I appreciate Justin's comment that they can used simply as a way to > > > keep code organized - I have done similar type of coding (using > > > methods and attributes) with Actionscript, and this worked well for me > > > in the past. > > > I used pymel for awhile, but found that, as a one person shop, it was > > > too hard to keep track of what is pymel vs. what is python, so for now > > > I'm sticking to python. > > > > > Also, regarding the use of the object param to create a new style > > > class - I read up on that. Is it correct that that is now optional > > > and all classes are automatically cast as they type 'object'? > > > > > Thanks for the help and feedback. > > > > > -- > > > view archives:http://groups.google.com/group/python_inside_maya > > > change your subscription settings: > > > > http://groups.google.com/group/python_inside_maya/subscribe > > -- > view archives: http://groups.google.com/group/python_inside_maya > change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe > -- Martin La Land Romero www.martinromerovfx.com http://martinromerovfx.blogspot.com/ [email protected] (415)261-2172 -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe
