Added new InventoryAction to import (localize) reference in Maya

PYPE-1399
This commit is contained in:
Petr Kalis 2021-09-13 13:35:24 +02:00
parent cb5585659d
commit 0adcf3334a
2 changed files with 28 additions and 0 deletions

View file

@ -35,6 +35,7 @@ def install():
pyblish.register_plugin_path(PUBLISH_PATH)
avalon.register_plugin_path(avalon.Loader, LOAD_PATH)
avalon.register_plugin_path(avalon.Creator, CREATE_PATH)
avalon.register_plugin_path(avalon.InventoryAction, INVENTORY_PATH)
log.info(PUBLISH_PATH)
menu.install()

View file

@ -0,0 +1,27 @@
from maya import cmds
from avalon import api
class ImportReference(api.InventoryAction):
"""Imports selected reference inside the file."""
label = "Import Reference"
icon = "mouse-pointer"
color = "#d8d8d8"
def process(self, containers):
references = cmds.ls(type="reference")
for container in containers:
if container["loader"] != "ReferenceLoader":
print("Not a reference, skipping")
continue
reference_name = container["namespace"] + "RN"
if reference_name in references:
print("Importing {}".format(reference_name))
ref_file = cmds.referenceQuery(reference_name, f=True)
cmds.file(ref_file, importReference=True)