0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

python maya filePathEditor get all reference file

Last updated at Posted at 2023-06-28
def _get_scene_references():
    """
    List all the references in the current scene
    Return the reference node/attribute and the file path
    """
    cmds.filePathEditor(rf=True)
    referenced_files: List[Tuple[str, pathlib.Path]] = []

    # Get the referenced files from the file path editor
    for attribute in cmds.filePathEditor(q=True, lf="", ao=True) or []:
        try:
            # Skip the nodes that are from an other referenced scene
            if cmds.referenceQuery(attribute, isNodeReferenced=True):
                continue
        except RuntimeError:
            continue

        # If the attribute is a maya/alembic/... reference
        if cmds.nodeType(attribute) == "reference":
            file_path = cmds.referenceQuery(
                attribute, filename=True, withoutCopyNumber=True
            )
            referenced_files.append((attribute, pathlib.Path(file_path)))
            continue

        # Otherwise, just get the attribute for simple stuff like file nodes
        file_path = cmds.getAttr(attribute)

        # Skip references that have an empty file_path
        if len(file_path) == 0:
            continue

        referenced_files.append((attribute, file_path))

    # Make sure to not have duplicates in the references
    return list(set(referenced_files))
        
referenceFiles = _get_scene_references()
print(referenceFiles)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?