コード例 #1
0
ファイル: MFileIO.py プロジェクト: jonntd/banana.maya
 def bnn_importFile(cls, fileName, type='', preserveReferences=False,
                    nameSpace='', ignoreVersion=False):
     """Import a file into the current Maya session.
     
     Parameters
     ----------
     fileName : str
         File name to import.
     type : str, optional
         Type of the file to import.
     preserveReferences : bool, optional
         True if the references needs to be preserved.
     nameSpace : str, optional
         Namespace to use when importing the objects.
     ignoreVersion : bool, optional
         True to ignore the version.
     
     Returns
     -------
     list of maya.OpenMaya.MDagPath
         The top level transforms imported.
     """
     if not type:
         type = None
     
     if not nameSpace:
         nameSpace = None
     
     topLevelDagPaths = list(OpenMaya.bnn_MItDagHierarchy())
     OpenMaya.MFileIO.importFile(fileName, type, preserveReferences,
                                 nameSpace, ignoreVersion)
     return [dagPath for dagPath in OpenMaya.bnn_MItDagHierarchy()
             if not dagPath in topLevelDagPaths]
コード例 #2
0
ファイル: MDagPath.py プロジェクト: jonntd/banana.maya
 def bnn_findShapes(self, pattern='', recursive=False, intermediates=False):
     """Find the shapes nested below this node.
     
     Parameters
     ----------
     pattern : str, optional
         Path of the shape nodes to match. Wildcards are allowed.
     types : list of maya.OpenMaya.MFn.Type, optional
         Shape types to match.
     recursive : bool, optional
         True to search recursively.
     intermediates : bool, optional
         True to also consider the intermediate shapes.
     
     Returns
     -------
     list of maya.OpenMaya.MDagPath
         The DAG path objects of the shape nodes found. If no shape
         nodes were found, an empty list is returned.
     """
     iterator = OpenMaya.bnn_MItDagHierarchy(
         self, pattern=pattern, types=OpenMaya.MFn.kShape,
         recursive=recursive)
     if not intermediates:
         return [
             item for item in iterator
             if not OpenMaya.MFnDagNode(item).isIntermediateObject()]
     
     return list(iterator)
コード例 #3
0
ファイル: MDagPath.py プロジェクト: jonntd/banana.maya
 def bnn_findShape(self, pattern='', recursive=False, intermediates=False):
     """Find a shape nested below this node.
     
     Parameters
     ----------
     pattern : str, optional
         Name or path pattern of the shape node to match.
         Wildcards are allowed.
     recursive : bool, optional
         True to search recursively.
     intermediates : bool, optional
         True to also consider the intermediate shapes.
     
     Returns
     -------
     maya.OpenMaya.MDagPath
         The DAG path object of the shape node found. If no or
         multiple shape nodes were found, None is returned.
     
     Examples
     --------
     Retrieve the unique shape node of an object:
     
     >>> import banana.maya
     >>> banana.maya.patch()
     >>> from maya import OpenMaya, cmds
     >>> cmds.polyCube(name='cube')
     >>> cube = OpenMaya.MDagPath.bnn_get(pattern='cube')
     >>> cubeShape = cube.bnn_findShape()
     """
     iterator = OpenMaya.bnn_MItDagHierarchy(
         self, pattern=pattern, types=OpenMaya.MFn.kShape,
         recursive=recursive)
     if not intermediates:
         iterator = (
             item for item in iterator
             if not OpenMaya.MFnDagNode(item).isIntermediateObject())
     
     dagPath = None
     for item in iterator:
         if dagPath:
             return None
         
         dagPath = item
     
     return dagPath
コード例 #4
0
ファイル: MDagPath.py プロジェクト: jonntd/banana.maya
 def bnn_findChild(self, pattern='', types=None, recursive=False):
     """Find a child node.
     
     Parameters
     ----------
     pattern : str, optional
         Name or path pattern of the child node to match.
         Wildcards are allowed.
     types : list of maya.OpenMaya.MFn.Type, optional
         Node types to match.
     recursive : bool, optional
         True to search recursively.
     
     Returns
     -------
     maya.OpenMaya.MDagPath
         The DAG path object of the node found. If no or multiple
         nodes were found, None is returned.
     
     Examples
     --------
     Retrieve a transform then a shape node by inspecting the child of
     a given object:
     
     >>> import banana.maya
     >>> banana.maya.patch()
     >>> from maya import OpenMaya, cmds
     >>> cmds.polyCube(name='cube')
     >>> cmds.group('|cube', name='root')
     >>> root = OpenMaya.MDagPath.bnn_get('root')
     >>> cube = root.bnn_findChild(pattern='cube')
     >>> cubeShape = root.bnn_findChild(types=OpenMaya.MFn.kShape, recursive=True)
     """
     iterator = OpenMaya.bnn_MItDagHierarchy(
         self, pattern=pattern, types=types, recursive=recursive)
     dagPath = None
     for item in iterator:
         if dagPath:
             return None
         
         dagPath = item
     
     return dagPath
コード例 #5
0
ファイル: MDagPath.py プロジェクト: jonntd/banana.maya
 def bnn_findChildren(self, pattern='', types=None, recursive=False):
     """Find children nodes.
     
     Parameters
     ----------
     pattern : str, optional
         Name or path pattern of the children nodes to match.
         Wildcards are allowed.
     types : list of maya.OpenMaya.MFn.Type, optional
         Node types to match.
     recursive : bool, optional
         True to search recursively.
     
     Returns
     -------
     list of maya.OpenMaya.MDagPath
         The DAG path objects of the nodes found. If no nodes were
         found, an empty list is returned.
     """
     return list(OpenMaya.bnn_MItDagHierarchy(
         self, pattern=pattern, types=types, recursive=recursive))