Workbench – quick update

There were some minor and some major changes done today. I need to keep myself focused on getting the major stuff done where possible (I am oh so good at getting stuck in the nitty gritty stuff) but some of the minor things were causing errors that stopped me from testing the big stuff.

First up the ‘minor’ stuff. I had some circular importing between my commands and nodes modules. Obviously sometimes nodes will need to refer to commands for things like errors, warnings, getting the native node type (based on a string, for wrapping nodes), etc. Commands was also referring to nodes, which is the import I’ve removed. It was getting information about classes for node wrapping (so that getSelection can return node objects – I had to know what native node types should be wrapped by which classes). There was also a couple of logic checks to see if a node was an instance of a specific node class, but I found a way to rejig that logic.
The information about what classes wrap which native nodes now exists in a class which has its own module, to which nodes and commands can both refer.

I found an issue with my Node class __getattr__ method in that it was checking against the attributes of self but not of the superclasses. The new __getattr__ method looks like this:

#overwrite getattr magic method so that attributes are accessible using node.attrName
def __getattr__(self, attrName):
#this checks all super classes following the Method Resolution Order
for obj in [self] + self.__class__.mro():
if obj.__dict__.has_key(attrName):
return obj.__dict__[attrName]
#wrap the in-application attribute in the Attribute class
return Attribute(self, attrName=attrName)
except RuntimeError:
raise AttributeError(“{0} does not have an attribute \”{1}\”.”.format(, attrName))

Again it’s probably going to eat my formatting so just kinda… try to guess where the tabs go?

For the curious among you, the Attribute class wraps attributes in one handy line:
self.MPlug = node.MFn.findPlug(attrName, True)
The methods for getting and setting values, checking value type, etc all use that MPlug (again huge thanks to Austin J Baker).

I also started setting up some of the node Classes _buildMaya methods. To start with I just got the Group and Camera classes sorted, since they both have relatively few node-specific methods/parameters, and it’s a great chance to test out all of the Transform, Shape, and Node methods (Group inherits Transform and Node, and Camera inherits Shape and Node). It was also my first time testing out the attribute methods. There are a few things to tweak there – particularly I’m going to be doing all of the attribute type checking in a getType method, and then the getting and setting of attributes can deal specifically with getting and setting attributes. It’ll also mean I can very easily check attribute types (as I’ll have an option to return the types as python types where available). I probably won’t bother with that until I’ve got some more node classes sorted out though – I might have to add ‘returning all attribute types as pythonic types’ as a stretch goal for the assignment, leave myself a note on it, and move on. It works well enough for now, and by Friday I need to have all of the nodes written up, so I really need to keep up the pace.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s