Getting MFn type from string type name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi folks! I'm writing some code to traverse the scene, which should let users filter for specific node types. Ideally, I want the users calling my code to provide the string type name of the nodes they're after, e.g. "transform", or "aiStandardSurface" etc.
I'm using MItDependencyGraph under the hood. This can take a MFn.Type as a filter, to let us get specific types of node.
My trouble at the moment is I can't find a good way to map string node type names to MFn.Type values. One option I have is to not filter nodes at all and just query their MFnDependencyNode.typeName, but this is quite a bit slower in testing than filtering directly with MItDepdencyGraph.
So far, the one way I can see of doing is, is to take the string type name, then create a node of this type, then get the MFnDependencyNode.typeName of my created node, then delete the node. Obviously this is not ideal! Another approach would be to maintain a very large hardcoded dict mapping string type names to MFn.Types. I'd rather not do this though if possible as it's likely to need to change as we add/remove plugins from our pipeline.
Does anyone have a better solution?