I would like to find out if anyone has suggestions on how to create a script that can easily be edited to create a custom Maya node with just adding in some arbitrary values of any type.
Basically, I would want to be able to specify an attribute type (string type, float type, ect), and to be able to fill in the values for those types and have the script generate a custom node easily.
At this point of time, node type doesn’t really matter. More trying to make a system that can easily create custom nodes that can be made with a script to generate them with custom attributes as needed.
Thank you for your response @Theodox, I tried out the network node and realized that it’s not really the kind of functionality that I was hoping for. I think I didn’t explain properly what I wanted either.
I wanted to find out if I could have a .json file that acts as a “template” to fill in the data of a custom Maya API node as well as to be able to loop over multiple “templates” that will generate multiple custom nodes at the same time. I’m trying to see if there are alternative ways to create my own nodes without having to hard code a custom node?
What you want is doable up to a point – however you won’t actually get much benefit over simply using cmds to add custom attributes.
If you want nodes with predictable properties, you’ll basically need to have an MPxNode class for every type of node. That is good for searching – each nodetype will be unique – and for predictability, since you can then rely on the presence of named properties on your nodes. However, once you start dynamically adding properties you won’t be able to rely on the presence of different attributes – effectively you’ll have to use your custom nodes as if they were networks with custom attributes.
You can definitely write some code to make it eaiser to generate new plugin node types faster, but in the end custom nodes want to be predictable and determinate, where custom attributes are more general but less predictable. There’s not going to be much of a sweet spot in the middle, although maybe you could do a mix of a small number of base types with a larger variety of custom attributes. I’m pretty sure the only opportunity to register a new node type is when the plugin that defines it is loaded (I could be wrong about that – but that’s how I rememember it.) You need to call OpenMaya.MFnPlugin.registerNode to tell Maya about the existence of the node, and that requires a handle to the plugin. It might be possible to implement a separate command in the same plugin to create and register a new node based on, say, a json file – but you’d have to run that script every time the plugin loads and you’d have to handle the case of json files moving or changing between runs.
You will also need to decide how you want to distribute things: user’s won’t get access to your custom nodes if they don’t have the plugin(s) which define them. Network + custom attributes will not have any external dependencies.
In general, if you want the nodes to be configurable on the fly I’d stick with networks and custom attributes. MPxNodes work better as static code – that way you have built in mechanisms for version changes and updating out-of-date data.
The last chapter is about this.
It builds a basic structure with a bit of metaprogramming using python’s type() and the factory pattern to build MpxNodes without all the boilerplate at runtime.
Might be what you’re looking for
Thank you very much for sharing. I actually have this book and was about two chapters away. It definitely has the approach what I am looking for in general. It will be a great reference to work off of.
Sounds like you’re after something like our MetaData API to bind, return and deal with node specific data under a managed system. Everything we do withing Red9 runs this metaData api under the hood and it’s particularly good at managing and building up rigging networks. The base of the API is open source and also on the Exchange App site:
Lots of demo videos on our vimeo page too:
Log in to Vimeo, the Develop Conference talk might be of interest
All of the attr handling for dealing with, encoding and decoding complex data to attrs on the nodes is also dealt with internally, great for storing things like zeroposes out to the nodes