Package mrv :: Package maya :: Module ref :: Class FileReference
[hide private]
[frames] | no frames]

Class FileReference

source code

         object --+        
                  |        
interface.Interface --+    
                      |    
     interface.iDagItem --+
                          |
                         FileReference

Represents a Maya file reference
Notes:
Instance Methods [hide private]

Inherited from interface.Interface: supports

Inherited from object: __delattr__, __format__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

    Object Overrides
 
__init__(self, filepath=None, refnode=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__eq__(self, other)
Special treatment for other filereferences
source code
 
__ne__(self, other) source code
 
__hash__(self)
hash(x)
source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
repr(x)
source code
    Reference Adjustments
 
remove(self, **kwargs)
Remove the given reference from the scene
source code
 
replace(self, filepath)
Replace this reference with filepath
source code
 
importRef(self, depth=0)
Import the reference until the given depth is reached
source code
    Nodes Query
 
iterNodes(self, *args, **kwargs)
Creates iterator over nodes in this reference
source code
    Edit
 
cleanup(self, unresolvedEdits=True, editTypes=editTypes)
remove unresolved edits or all edits on this reference
source code
 
setLocked(self, state)
Set the reference to be locked or unlocked
source code
 
setLoaded(self, state)
set the reference loaded or unloaded
source code
 
setNamespace(self, namespace)
set the reference to use the given namespace
source code
    Query
 
exists(self)
Returns: True if our file reference exists in maya
source code
 
isLocked(self)
Returns: True if reference is locked
source code
 
isLoaded(self)
Returns: True if the reference is loaded
source code
 
copynumber(self)
Returns: the references copy number - starting at 0 for the first reference
source code
 
namespace(self)
Returns: namespace object of the full namespace holding all objects in this reference
source code
 
path(self, copynumber=False, unresolved=False)
Returns: Path object with the path containing the reference's data
source code
 
referenceNode(self)
Returns: wrapped reference node managing this reference
source code
    Query Methods
 
parent(self)
Returns: the parent reference of this instance or None if we are root
source code
 
children(self, predicate=lambda x: True)
Returns: all intermediate child references of this instance
source code

Inherited from interface.iDagItem: basename, childrenDeep, isPartOf, isRoot, isRootOf, parentDeep, root

    Iterators

Inherited from interface.iDagItem: iterParents

    Name Generation

Inherited from interface.iDagItem: fullChildName

Class Methods [hide private]
 
_splitCopyNumber(cls, path)
Returns: (path, copynumber), copynumber is at least 0
source code
    Reference Adjustments
 
create(cls, filepath, namespace=None, load=True, **kwargs)
Create a reference with the given namespace
source code
    Listing
 
fromPaths(cls, paths, **kwargs)
Find the reference for each path in paths.
source code
 
ls(cls, rootReference="", predicate=lambda x: True)
list all references in the scene or under the given root
source code
 
lsDeep(cls, predicate=lambda x: True, **kwargs)
Return all references recursively
source code
    Name Generation

Inherited from interface.iDagItem: addSep

Class Variables [hide private]
  editTypes = ['setAttr', 'addAttr', 'deleteAttr', 'connectAttr'...

Inherited from interface.iDagItem: kOrder_BreadthFirst, kOrder_DepthFirst

    Configuration
  _sep = '/'
hash(x)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

_splitCopyNumber(cls, path)
Class Method

source code 
Returns:
(path, copynumber), copynumber is at least 0

__init__(self, filepath=None, refnode=None)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

__hash__(self)
(Hashing function)

source code 

hash(x)

Overrides: object.__hash__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

create(cls, filepath, namespace=None, load=True, **kwargs)
Class Method

source code 
Create a reference with the given namespace
Parameters:
  • filepath - path describing the reference file location
  • namespace - if None, a unique namespace will be generated for you The namespace will contain all referenced objects.
  • load - if True, the reference will be created in loaded state, other wise its loading is deferred
  • kwargs - passed to file command
Raises:
  • ValueError - if the namespace does already exist
  • RuntimeError - if the reference could not be created

remove(self, **kwargs)

source code 
Remove the given reference from the scene
Decorators:
  • @undo.notundoable
Notes:
  • assures that no namespaces of that reference are left, remaining objects will be moved into the root namespace. This way the namespaces will not be left as waste. This fails if there are referenced objects in the subnamespace - we currently ignore that issue as the main reference removal worked at that point.
  • kwargs passed to namespace.delete

replace(self, filepath)

source code 
Replace this reference with filepath
Parameters:
  • filepath - the path to the file to replace this reference with Reference instances will be handled as well.
Returns:
self
Decorators:
  • @undo.notundoable

importRef(self, depth=0)

source code 
Import the reference until the given depth is reached
Parameters:
  • depth -
    • x<1: import all references and subreferences

    • x: import until level x is reached, 0 imports just self such that

      all its children are on the same level as self was before import

Returns:
list of FileReference objects that are now in the root namespace - this list could be empty if all subreferences are fully imported
Decorators:
  • @undo.notundoable

fromPaths(cls, paths, **kwargs)
Class Method

source code 
Find the reference for each path in paths. If you provide the path X 2 times, but you only have one reference to X, the return value will be [FileReference(X), None] as there are less references than provided paths.
Parameters:
  • paths - a list of paths or references whose references in the scene should be returned. In case a reference is found, its plain path will be used instead.
  • kwargs - all supported by ls to yield the base set of references we will use to match the paths with. Additionally, you may specify:

    • ignore_extension:

      if True, default False, the extension will be ignored during the search, only the actual base name will matter. This way, an MA file will be matched with an MB file. The references returned will still have their extension original extension.

Returns:
list(FileReference|None, ...) if a filereference was found for given occurrence of Path, it will be returned at index of the current path in the input paths, otherwise it is None.

Note: zip(paths, result) to get a corresponding tuple list associating each input path with the located reference

ls(cls, rootReference="", predicate=lambda x: True)
Class Method

source code 
list all references in the scene or under the given root
Parameters:
  • rootReference - if not empty, the references below it will be returned. Otherwise all scene references will be listed. May be string, Path or FileReference
  • predicate - method returning true for each valid file reference object that should be part of the return value.
Returns:
list of FileReference s objects

lsDeep(cls, predicate=lambda x: True, **kwargs)
Class Method

source code 
Return all references recursively
Parameters:
  • kwargs - support for arguments as in ls, hence you can use the rootReference flag to restrict the set of returned FileReferences.

iterNodes(self, *args, **kwargs)

source code 
Creates iterator over nodes in this reference
Parameters:
  • args - MFn.kType filter ids to be used to pre-filter all nodes. If you know what you are looking for, setting this can greatly improve performance !
  • kwargs - additional kwargs will be passed to either iterDagNodes or iterDgNodes (dag = False). The following additional kwargs may be specified:

    • asNode:

      if True, default True, return wrapped Nodes, if False MDagPaths or MObjects will be returned

    • dag:

      if True, default False, return dag nodes only. Otherwise return dependency nodes as well. Enables assemblies and assembilesInReference.

    • assemblies:

      if True, return only dagNodes with no parent. Needs dag and is mutually exclusive with assembilesInReference.

    • assembliesInReference:

      if True, return only dag nodes that have no parent in their own reference. They may have a parent not coming from their reference though. This flag has a big negative performance impact and requires dag.

    • predicate:

      if function returns True for Node|MObject|MDagPath n, n will be yielded. Defaults to return True for all.

Raises:
  • ValueError - if incompatible arguments have been given

cleanup(self, unresolvedEdits=True, editTypes=editTypes)

source code 
remove unresolved edits or all edits on this reference
Parameters:
  • unresolvedEdits - if True, only dangling connections will be removed, if False, all reference edits will be removed - the reference will be unloaded for beforehand. The loading state of the reference will stay unchanged after the operation.
  • editTypes - list of edit types to remove during cleanup
Returns:
self
Decorators:
  • @undo.notundoable

setLocked(self, state)

source code 
Set the reference to be locked or unlocked
Parameters:
  • state - if True, the reference is locked , if False its unlocked and can be altered
Returns:
self
Decorators:
  • @undo.notundoable

setLoaded(self, state)

source code 
set the reference loaded or unloaded
Parameters:
  • state - True = unload reference, True = load reference
Returns:
self
Decorators:
  • @undo.notundoable

setNamespace(self, namespace)

source code 
set the reference to use the given namespace
Parameters:
  • namespace - Namespace instance or name of the short namespace
Returns:
self
Decorators:
  • @undo.notundoable
Raises:
  • RuntimeError - if namespace already exists or if reference is not root

parent(self)

source code 
Returns:
the parent reference of this instance or None if we are root
Overrides: interface.iDagItem.parent

children(self, predicate=lambda x: True)

source code 
Parameters:
  • predicate - return True to include x in result
Returns:
all intermediate child references of this instance
Overrides: interface.iDagItem.children

exists(self)

source code 
Returns:
True if our file reference exists in maya

isLocked(self)

source code 
Returns:
True if reference is locked

isLoaded(self)

source code 
Returns:
True if the reference is loaded

copynumber(self)

source code 
Returns:
the references copy number - starting at 0 for the first reference

Note: we do not cache the copy number as mayas internal numbering can change on when references change - the only stable thing is the reference node name

namespace(self)

source code 
Returns:
namespace object of the full namespace holding all objects in this reference

path(self, copynumber=False, unresolved=False)

source code 
Parameters:
  • copynumber - If True, the returned path will include the copy number. As it will be a path object, it might not be fully usable in that state
  • unresolved - see ls
Returns:
Path object with the path containing the reference's data

Note: we always query it from maya as our numbers change if some other reference is being removed and cannot be trusted

referenceNode(self)

source code 
Returns:
wrapped reference node managing this reference

Class Variable Details [hide private]

editTypes

Value:
['setAttr', 'addAttr', 'deleteAttr', 'connectAttr', 'disconnectAttr', \
'parent']