get_dagpath_from_name( node_name )
This is the first post of it’s kind where I will post a useful function that can be used to build up your library.
I find myself bouncing between maya.cmds and maya.api.OpenMaya quite a bit, and have run into the issue of converting string names objects that can be used with OpenMaya operations. Here is a simple function that will get a maya.api.OpenMaya.MDagPath object from the given node name.
import maya.api.OpenMaya import maya.cmds def get_dagpath_from_name( node_name ): """ Gets a node's MDagPath object from it's name. args: node_name: string | The name of the node. kwargs: return: MDagPath if successful, None otherwise. """ selection_list = OpenMaya.MSelectionList( ) if not maya.cmds.objExists( node_name ): return None selection_list.add( node_name ) dag_path = selection_list.getDagPath( 0 ) return dag_path