Package mrv :: Package maya :: Package nt :: Module base
[hide private]
[frames] | no frames]

Module base

source code

Contains some basic classes that are required to run the nodes system

All classes defined here can replace classes in the node type hierarachy if the name matches. This allows to create hand-implemented types.

Classes [hide private]
  ContainerBase
  Entity
    Base
  Node
Common base for all maya nodes, providing access to the maya internal object representation Use this class to directly create a maya node of the required type
  NodeFromObj
Virtual Constructor, producing nodes as the Node does, but it will only accept MObjects or dagpaths which are expected to be valid.
  NodeFromStr
Virtual constructor similar to NodeFromObj, but it will only accept strings to produce a wrapped node as fast as possible.
  DependNode
Implements access to dependency nodes
  DagNode
Implements access to DAG nodes
    Utilities
  SetFilter
Utility Class returning True or False on call, latter one if the passed object does not match the filter
    Attributes
  Attribute
Represents an attribute in general - this is the base class Use this general class to create attribute wraps - it will return a class of the respective type
  UnitAttribute
  TypedAttribute
  NumericAttribute
  MessageAttribute
  MatrixAttribute
  LightDataAttribute
  GenericAttribute
  EnumAttribute
  CompoundAttribute
    Data
  Data
Represents an data in general - this is the base class Use this general class to create data wrap objects - it will return a class of the respective type
  VectorArrayData
  UInt64ArrayData
  StringData
  StringArrayData
  SphereData
  PointArrayData
  PluginData
Wraps plugin data as received by a plug.
  NumericData
  NObjectData
  NIdData
  MatrixData
  IntArrayData
  GeometryData
Wraps geometry data providing additional convenience methods
  SubdData
  NurbsSurfaceData
  NurbsCurveData
  MeshData
  LatticeData
  DynSweptGeometryData
  DoubleArrayData
  ComponentListData
Improves the default wrap by adding some required methods to deal with component lists
  ArrayAttrsData
    Components
  Component
Represents a shape component - its derivates can be used to handle component lists to be used in object sets and shading engines
  SingleIndexedComponent
precreated class for ease-of-use
  DoubleIndexedComponent
Fixes some functions that would not work usually
  TripleIndexedComponent
precreated class for ease-of-use
    Basic Types
  MDagPathUtil
Performs operations on MDagPaths which are hard or inconvenient to do otherwise
    Default Types
  Reference
Implements additional utilities to work with references
  Transform
Precreated class to allow isinstance checking against their types and to add undo support to MFnTransform functions, as well as for usability
  Shape
Interface providing common methods to all geometry shapes as they can be shaded.
Functions [hide private]
 
_checkedInstanceCreationDagPathSupport(mobject_or_mdagpath, clsToBeCreated, basecls)
Same purpose and attribtues as _checkedInstanceCreation, but supports dagPaths as input as well
source code
 
_checkedInstanceCreation(apiobj, typeName, clsToBeCreated, basecls)
Utiliy method creating a new class instance according to additional type information Its used by __new__ constructors to finalize class creation
source code
 
_setupDagNodeDelayedMethods(dagnode, mobject, mdagpath)
Setup the given dagnode with the instance methods it needs to handle the gven mobject OR mdagpath accordingly, one of them may be None
source code
 
_createInstByPredicate(apiobj, cls, basecls, predicate)
Allows to wrap objects around MObjects where the actual compatabilty cannot be determined by some nodetypename, but by the function set itself.
source code
 
_getUniqueName(dagpath)
Create a unique name based on the given dagpath by appending numbers
source code
    Conversions
 
nodeTypeToNodeTypeCls(nodeTypeName, apiobj)
Convert the given node type (str) to the respective python node type class
source code
 
_makeAbsolutePath(nodename) source code
 
isAbsolutePath(nodename) source code
 
toDagPath(apiobj)
Find ONE valid dag path to the given dag api object
source code
 
toApiobj(nodename)
Convert the given nodename to the respective MObject
source code
 
toApiobjOrDagPath(nodename)
Convert the given nodename to the respective MObject or MDagPath
source code
 
toSelectionList(nodeList, mergeWithExisting=False)
Convert an iterable filled with Nodes to a selection list
source code
 
toComponentSelectionList(nodeCompList, mergeWithExisting=False)
As above, but only works on DagNodes having components - the components can be a nullObject though to add the whole object after all.
source code
 
toSelectionListFromNames(nodenames)
Convert the given iterable of nodenames to a selection list
source code
 
fromSelectionList(sellist, handlePlugs=1, **kwargs)
Returns: list of Nodes and MPlugs stored in the given selection list
source code
 
toNodesFromNames(nodenames, **kwargs)
Returns: list of wrapped nodes from the given list of node names
source code
 
findByName(name, **kwargs)
Returns: list of node matching name, whereas simple regex using * can be used to describe a pattern
source code
    Base
 
objExists(objectname)
Returns: True if given object exists, false otherwise
source code
 
delete(*args, **kwargs)
Delete the given nodes
source code
 
selection(filterType=api.MFn.kInvalid, **kwargs)
Returns: list of Nodes from the current selection
source code
 
activeSelectionList()
Returns: MSelectionList of the current selection list
source code
 
iterSelection(filterType=api.MFn.kInvalid, **kwargs)
Returns: iterator over current scene selection
source code
 
select(*nodesOrSelectionList, **kwargs)
Select the given list of wrapped nodes or selection list in maya
source code
 
createNode(nodename, nodetype, autocreateNamespace=True, renameOnClash=True, forceNewLeaf=True, maxShapesPerTransform=0)
Create a new node of nodetype with given nodename
source code
 
_lookup_type(mobject_or_mdagpath)
Returns: node type name of the given MObject or MDagPath
source code
    Attributes
 
_new_mixin(cls, *args, **kwargs)
Constructor for MObject derived types which only differ in a few parameters.
source code
Variables [hide private]
  log = logging.getLogger("mrv.maya.nt.base")
  _nodesdict = None
hash(x)
  _nameToApiSelList = api.MSelectionList()
  _mfndep = api.MFnDependencyNode()
  _mfndag = api.MFnDagNode()
  _mfndep_setobject = _mfndep.setObject
  _mfndag_setObject = _mfndag.setObject
  _mfndep_typename = _mfndep.typeName
  _mfndag_typename = _mfndag.typeName
  _mfndep_name = _mfndep.name
  _api_mdagpath_node = MDagPath.node
  _apitype_to_name = dict()
  _plugin_type_ids = api.MFn.kPluginDeformerNode, api.MFn.kPlugi...
  _plugin_type_ids_lut = set(_plugin_type_ids)
  _plugin_type_to_node_type_name = dict(zip((_plugin_type_ids), ...
    Base
  _api_type_tuple = MObject, MDagPath
Function Details [hide private]

nodeTypeToNodeTypeCls(nodeTypeName, apiobj)

source code 
Convert the given node type (str) to the respective python node type class
Parameters:
  • nodeTypeName - the type name you which to have the actual class for
  • apiobj - source api object, its apiType is used as fallback in case we don't know the node

toApiobj(nodename)

source code 
Convert the given nodename to the respective MObject
Notes:
  • uses unique names only, and will fail if a non-unique path is given, which is as selection lists do not work properly with partial names !
  • even dag objects will end up as MObject
  • code repeats partly in toApiobjOrDagPath as its supposed to be as fast as possible - this method gets called quite a few times in benchmarks

toApiobjOrDagPath(nodename)

source code 
Convert the given nodename to the respective MObject or MDagPath

Note: we treat "nodename" and "|nodename" as the same objects as they occupy the same namespace - one time a dep node is meant, the other time a dag node. If querying a dag node, the dep node with the same name is not found, although it is in the same freaking namespace ! IMHO this is a big bug !

toSelectionList(nodeList, mergeWithExisting=False)

source code 
Convert an iterable filled with Nodes to a selection list
Parameters:
  • nodeList - iterable filled with dg and dag nodes as well as plugs, dagpaths or mobjects or strings
  • mergeWithExisting - if true, the selection list will not allow dupliacates , but adding objects also takes (much) longer, depending on the size of the list
Returns:
selection list filled with objects from node list

toComponentSelectionList(nodeCompList, mergeWithExisting=False)

source code 
As above, but only works on DagNodes having components - the components can be a nullObject though to add the whole object after all.
Parameters:
  • nodeCompList - list of tuple(DagNode, Component), Component can be filled component or null MObject

toSelectionListFromNames(nodenames)

source code 
Convert the given iterable of nodenames to a selection list
Returns:
MSelectionList, use iterSelectionList to retrieve the objects

fromSelectionList(sellist, handlePlugs=1, **kwargs)

source code 
Parameters:
  • kwargs - passed to selectionListIterator
Returns:
list of Nodes and MPlugs stored in the given selection list

toNodesFromNames(nodenames, **kwargs)

source code 
Parameters:
Returns:
list of wrapped nodes from the given list of node names

Note: this function is supposed to be faster for multiple nodes compared to just creating a Node directly as we optimize the process due to the intermediate selection list getting the api objects for the given names

findByName(name, **kwargs)

source code 
Parameters:
  • name - string like pcube, or pcube*, or pcube*|*Shape
  • kwargs - passed to fromSelectionList
Returns:
list of node matching name, whereas simple regex using * can be used to describe a pattern

objExists(objectname)

source code 
Parameters:
  • objectname - we always use absolute paths to have a unique name
Returns:
True if given object exists, false otherwise

Note: perfer this method over mel as the API is used directly as we have some special handling to assure we get the right nodes

delete(*args, **kwargs)

source code 
Delete the given nodes
Parameters:
  • args - Node instances, MObjects, MDagPaths or strings to delete
  • kwargs -
    • presort:

      if True, default False, will do alot of pre-work to actually make the deletion work properly using the UI, thus we sort dag nodes by dag path token length to delete top level ones first and individually, to finally delete all dependency nodes in a bunch

    Using this flag will be slower, but yields much better results if deleting complex dag and dependency trees with locked attributes, conversion nodes, transforms and shapes

Decorators:
  • @undoable
Notes:
  • in general , no matter which options have been chosen , api deletion does not work well as the used algorithm is totally different and inferior to the mel implementaiton
  • will not raise in case of an error, but print a notification message
  • all deletions will be stored on one undo operation

selection(filterType=api.MFn.kInvalid, **kwargs)

source code 
Parameters:
  • filterType - The type of nodes to return exclusively. Defaults to returning all nodes.
  • kwargs - passed to fromSelectionList
Returns:
list of Nodes from the current selection

activeSelectionList()

source code 
Returns:
MSelectionList of the current selection list

iterSelection(filterType=api.MFn.kInvalid, **kwargs)

source code 
Parameters:
  • filterType - MFn type specifying the node type to iterate upon. Defaults to all node types.
  • kwargs - passed to it.iterSelectionList
Returns:
iterator over current scene selection

Note: This iterator will always return Nodes

select(*nodesOrSelectionList, **kwargs)

source code 
Select the given list of wrapped nodes or selection list in maya
Parameters:
  • nodesOrSelectionList - single selection list or multiple wrapped nodes , or multiple names
  • kwargs -
    • listAdjustment: default api.MGlobal.kReplaceList
Notes:
  • as this is a convenience function that is not required by the api itself, but for interactive sessions, it will be undoable
  • Components are only supported if a selection list is given
  • This method is implicitly undoable

createNode(nodename, nodetype, autocreateNamespace=True, renameOnClash=True, forceNewLeaf=True, maxShapesPerTransform=0)

source code 
Create a new node of nodetype with given nodename
Parameters:
  • nodename - like mynode``or ``namespace:mynode or |parent|mynode or |ns1:parent|ns1:ns2:parent|ns3:mynode. The name may contain any amount of parents and/or namespaces.
  • nodetype - a nodetype known to maya to be created accordingly
  • autocreateNamespace - if True, namespaces given in the nodename will be created if required
  • renameOnClash - if True, nameclashes will automatcially be resolved by creating a unique name - this only happens if a dependency node has the same name as a dag node
  • forceNewLeaf - if True, nodes will be created anyway if a node with the same name already exists - this will recreate the leaf portion of the given paths. Implies renameOnClash If False, you will receive an already existing node if the name and type matches.
  • maxShapesPerTransform - only used when renameOnClash is True, defining the number of shapes you may have below a transform. If the number would be exeeded by the creation of a shape below a given transform, a new auto-renamed transform will be created automatically. This transform is garantueed to be new and will be used as new parent for the shape.
Returns:
the newly create Node
Decorators:
  • @undoable
Raises:
  • RuntimeError - If nodename contains namespaces or parents that may not be created
  • NameError - If name of desired node clashes as existing node has different type
Notes:
  • For reasons of safety, dag nodes must use absolute paths like |parent|child - otherwise names might be ambiguous ! This method will assume absolute paths !
  • As this method is checking a lot and tries to be smart, its relatively slow (creates ~1200 nodes / s)

_checkedInstanceCreation(apiobj, typeName, clsToBeCreated, basecls)

source code 
Utiliy method creating a new class instance according to additional type information Its used by __new__ constructors to finalize class creation
Parameters:
  • apiobj - the MObject or MDagPath of object to wrap
  • typeName - the name of the node type to be created
  • clsToBeCreated - the cls object as passed in to __new__
  • basecls - the class of the caller containing the __new__ method
Returns:
create clsinstance if the proper type (according to nodeTypeTree)

_createInstByPredicate(apiobj, cls, basecls, predicate)

source code 
Allows to wrap objects around MObjects where the actual compatabilty cannot be determined by some nodetypename, but by the function set itself. Thus it uses the nodeTypeToMfnClsMap to get mfn cls for testing
Parameters:
  • cls - the class to be created
  • basecls - the class where __new__ has actually been called
  • predicate - returns true if the given nodetypename is valid, and its mfn should be taken for tests
Returns:
new class instance, or None if no mfn matched the apiobject

_lookup_type(mobject_or_mdagpath)

source code 
Returns:
node type name of the given MObject or MDagPath

Note: if we have a plugin type, we must use the 'slow' way as the type is the same for all plugin nodes

_new_mixin(cls, *args, **kwargs)

source code 

Constructor for MObject derived types which only differ in a few parameters. Requires _base_cls_ and _mfn_suffix_ to be set on the respective class

return an attribute class of the respective type for given MObject

Parameters:
  • args - arg[0] is attribute's MObject to be wrapped.

Note: Custom constructors are not possible as __init__ is automatically called afterwards - MObject does not support anything but no args or another MObject.


Variables Details [hide private]

_plugin_type_ids

Value:
api.MFn.kPluginDeformerNode, api.MFn.kPluginDependNode, api.MFn.kPlugi\
nEmitterNode, api.MFn.kPluginFieldNode, api.MFn.kPluginHwShaderNode, a\
pi.MFn.kPluginIkSolver, api.MFn.kPluginImagePlaneNode, api.MFn.kPlugin\
LocatorNode, api.MFn.kPluginManipContainer, api.MFn.kPluginObjectSet, \
api.MFn.kPluginParticleAttributeMapperNode, api.MFn.kPluginShape, api.\
MFn.kPluginSpringNode, api.MFn.kPluginTransformNode

_plugin_type_to_node_type_name

Value:
dict(zip((_plugin_type_ids), ("UnknownPluginDeformerNode", "UnknownPlu\
ginDependNode", "UnknownPluginEmitterNode", "UnknownPluginFieldNode", \
"UnknownPluginHwShaderNode", "UnknownPluginIkSolver", "UnknownPluginIm\
agePlaneNode", "UnknownPluginLocatorNode", "UnknownPluginManipContaine\
r", "UnknownPluginObjectSet", "UnknownPluginParticleAttributeMapperNod\
e", "UnknownPluginShape", "UnknownPluginSpringNode", "UnknownPluginTra\
nsformNode")))