Monday, July 27, 2015

Interesting Things with the Maya Python Api

I have found the API becomes a lot easier to understand as you realise how attributes are inherited between classes. Also, if you read this and see that I am incorrect, please correct me. I am writing this as I learn and this is being written down as best as I understand. Writing it almost helps unravel my thought process and break the concepts and problems down into their raw data. Thus making the information easier to understand.
So I was writing a default dependency node template. As I am writing this I am trying to understand why each of the pieces of a node are there, and what they do. Each time I need to use a piece of code, I will refer to the API guide and understand where the command or attribute had come from and how it is returning the data.
The interesting one I just came accross was when working with a MFnNumericAttribute class. I was using this in the initialize() function where the different attributes are built for the dependency node.
What I found was when I came to set the attribute to keyable, storable etc, I could not find any information relating to these attributes in the documentation for MFnNumericAttribute. This is where I realised that these attributes were being inherited from the parent class, MFnAttribute. So by creating a MFnNumericAtribute, I had access to all the attributes associated with this command, but I also had access to everything above. So:

nAttr = OpenMaya.MFnNumericAttribute()
#now you can access attributes from MFnAttribute
#or attributes from MFnNumericAttribute

Ok I know this is super novice. But one thing I realised when I was starting to learn, is these little things can really help learn how to read the documentation, and I couldn't find that info anywhere out there, a lot of it was assumed knowledge. That being said, to find the information for yourself means that you will always remember it and understand how to apply that same knowledge to different scenarios.
Once I'm done with my default node template I'll bang it up here. Cheers.

1 comment: