what would I use to allow the plugin to read an external user specified file, either a txt or json?
You could make a string attribute on the node, and set MFnAttribute::isUsedAsFilename = true
, which will let users browse for a file.
Once you’ve got access to a path from C++, have a look at RapidJSON or nlohmann/json for a fast or convenient option, in that order. They’re both header-only and work just fine with something like Maya. You’ll likely get more options from others, because there are just so many options here. If you drill down into more specifics about your requirements, e.g. should it be human-readable? Does it need to be JSON? Does it need to be small? Network friendly? Is the data large, like a pointcache or small like a set of attributes? Will you be serialising data? Would you need something that can be deserialised into the same data structure? Etc.
is there a way to have a C++ plugin run python at all?
Yes, you can either call on Maya’s Python from C++ via MGlobal::executePythonCommand("print('hello world!')");
or you can embed another Python yourself and call that. The latter would have the benefit of not polluting the global Python namespace and memory, and is something you could use to spin up multiple Python interpreters in parallel if your code is performance sensitive (though I’d question why you’d turn to Python in that case).
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABBPk35P29DnsEqw3Chjv%2Biy0GuHkRFDOaf-jJx_o5moTA1e%2Bg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC8cVw97ZeVtLanizhcdCzSwjbr5OY_%2BCDd0UJ-5iipdQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABBPk34qLGDCYOqxnck7y-o1LYaZRaSa%3D1OB4CdE%2BZXuqE3aRg%40mail.gmail.com.
As a side note, for generic use (outside of maya) you can use boost python to call python from C++ and vice versa:
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMQ7LY0OBFdE8t%2BJAs4z5VizR-X-ZHMCY5HgDaS0%3DDCjkg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1sZj%2BYZ9VxCo66u5sUOrndB4BQSKh-h-YEOWLTWLd%3DuA%40mail.gmail.com.
pybind11 is great, but it is increeeedibly slow to compile. Like 20 seconds for a handful of bound methods. It’s insane.
That aside, I’ve got a recent project that might make a good example of what it is and how it can be used to re-create the Maya Python API.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMQfvbc0AG%3D6hCLAU%3DyhTsOm2mQuC7vufgif9NFWzfa-uQ%40mail.gmail.com.
pybind11 is great, but it is increeeedibly slow to compile. Like 20 seconds for a handful of bound methods. It’s insane.
That aside, I’ve got a recent project that might make a good example of what it is and how it can be used to re-create the Maya Python API.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBs2U%3D_dEcPa%2BgxdV_gYLr6wL%3Dgs3kfXm1xpY%3DGNFYVgQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1S1XFqRin%3D-zzgtZ6dMvcQcaU1WrF-8EVvb8kGDEqedQ%40mail.gmail.com.
It would only be computed outputMatrix
is pulled, so a first step is testing that.
cmds.setAttr(yourNode + ".PoseFile", "changed.txt", type="string")
# Compute not called yet..
cmds.getAttr(yourNode + ".outputMatrix")
# Compute called
If that doesn’t happen, it’s possible strings aren’t part of normal evaluation. Try making the attribute a setInternalValue
instead. It’ll notify you whenever the value changes, which is probably what you want anyway, since it can only ever be updated manually by the user or Python (rather than a connection). If that doesn’t work, then another option is to implement MNodeMessage::addNodeDirtyPlugCallback
to check for it yourself.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABBPk363E1xp0vcgBwMJ5x%2Bgd5YpGhTj_z2MDyPQE0XF35yDdw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAB7eYGyr67ymJNAUiFxKNBWJ7cf0kY8nXTUgdsJimUSQ%40mail.gmail.com.