Hi, I am a rigger, and I started using Python and OOP for my tools about 2 years ago. I don't know if my way of doing things is the proper one, but it is one of the many :)
I have a utility module, where I have collected a lot of utility functions that do not need a class, f.e. naming utilities, setting up attributes, math functions, lockAndHide functions and such. Those are used through all the tools. Then I have a base class, where all the things I do in every setup are done: all input check functions, common functions that I know every or most setups will do (like parenting into proper hierarchy, getting some joint info, message connecting and such), and all cleanup functions. Then I have some first-level tools that derive from that base class, like ik-fk switch setup class, pole vector class, simple fk control class and such. They are separate classes because I use this functionality in many different setups, and some times on their own. And finally the top-level setups, like ik-fk arm, which is derived from the base class, and use functionality of the first-level classes (just through calls). I take care to separate different parts of setup into different functions within the class, so later I can easy override only some of them. F.e. there will be a separate function that creates the IK setup, another one that does the FK setup, and so on. I create my first ik_fk arm setup, and then when I need slightly different functionality - I derive another class from that and override only the functionality that needs changing, that way reusing most of the code. F.e. I need a different way of doing IK setup - I override only that function, everything else comes from the first ik-fk arm setup class. Hope that makes sense. Sasha On Mon, Mar 11, 2013 at 1:59 PM, Simen Chris <[email protected]> wrote: > I'm trying to wrap my head around how I can utilize Python/PyMEL's OOP > functionality when writing rigging-tools, but I'm struggling to transfer > native Python examples over to Python in Maya. > > Lets say I'm working on a arm-rig script, and I want the option to choose > between four options (normal, FkIk, stretchy, elbowLock). > > The problem I've faced with MEL is that I have to write four separate > scripts to archieve this, because if I for instance want both FK/IK _and_ > elbowLock, there's a huge amount of if's needed to being able to re-use > code. Also, if I'm going to add another option later on there's gonna be > really messy. > > > I was hoping someone could provide an example of using OOP in a rig-tool? > Or maybe explain how to approach a script like the one I mentioned? I've > searched around for an example like this for weeks without any luck :( > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
