Home > Blockchain >  maya api save/keep data in memory generated by command?
maya api save/keep data in memory generated by command?

Time:10-28

I wrote a maya plugin (class).

Executing the plugin/command in maya will produce some data. Executing the plugin/command again in Maya will depend on the data generated after the last execution, but the data generated in the last execution will be destroyed with the destruction of the plugin class.How do I save/keep the data generated after a command is executed in memory?

Perhaps create custom nodes in the scene?Is there a better and more convenient way

CodePudding user response:

The only storable database in Maya is the node graph, and the attributes on the nodes. If you have written a command that is generating data in the DG, you probably should have written that as a node (where the input attributes are your function arguments, and the output attributes are the function outputs)

Typically you write an MPxCommand paired with an MPxNode. The command simply creates an instance of the node. When the -query flag is provided, you are returning data from the node attributes. When the -edit flag is present, you are modifying attributes on the node.

There is literally no way in Maya for an MPxCommand to store data other than by using the node graph (possibly optionVars to store user preferences, but that won't be tied to scene data).

Ignoring the fact that you probably want to be writing a node for now....

Either....

  1. create an instance of a node type that already exists (e.g. transform or set), and add custom attributes to store the data you need. Relationships to other nodes in the scene can be stored using connections (sets may work well if you need to refer to many objects). The data will now be serialised into the Maya binary/ascii file so your tool will still work once the scene is reloaded.
  2. Create a custom MPxNode, and do that same thing, but with a hardcoded set of attributes. This just means users can't delete the attributes, and you can get a bit more control over them (such as making them readonly, and possibly hoisting any computation out of your command, and moving it into the node's compute method).
  3. If the data you need to store doesn't fit into the existing attribute types, you may need to add an MPxData object (which can be stored on an attribute within a custom node). This is useful for large binary blobs of data.
  • Related