I’ve been working with Maya lately, using Python to build some animation utilities. In particular, my Camera Tool is in development to help manage a collection of perspective cameras within a scene, allowing a user to create and edit camera settings, without interfering with prime selection in the Maya viewports.
In building the UI and getting the functionality working, I started to recognise a simple structure for the code, and thought it might be worth sharing. As I have found out from having spent much of the last eight years creating tools for Maya and 3d Studio Max, one always adapts one’s working practices as one gets more accomplished. Consider this a snapshot in time of my current working methods. If you find it a useful structure, then that should help you loads. On the other hand, if you perceive weaknesses in the layout, get on my case. I want to improve as much as you do!
Organising the code blocks in this fashion allows us to have a nice simple layout so that we can easily manage, update and complicate the functionality. In my current version of the tool, all the code blocks are in one single Python file. This is fine for a simple tool, but by defining these blocks as distinct areas of the code, we can quite easily have the code blocks in different Python documents. For the sake of any of the commands that may be generic, it would be great to access such functionality directly from an independent module, so as to reduce the possibility of ‘revinventing the wheel’ as far as coding goes. Examples of such commands would be functions that query materials on collections of objects. Anything, that could be used in another tool.