Skip to main content

Reference collector plugin example

Create a maya_reference_collector.py file inside the plugins folder with the following content:

Please check the plugin extension section to know more.

# :coding: utf-8
# :copyright: Copyright (c) 2024 ftrack
import maya.cmds as cmds

from ftrack_framework_core.plugin import BasePlugin
from ftrack_framework_core.exceptions.plugin import PluginExecutionError


class MayaReferenceCollectorPlugin(BasePlugin):
name = 'maya_reference_collector'

# This is the method called by the UI to fetch information.
def ui_hook(self, payload):
'''
Return all available references in Maya
'''
# payload contains data passed by the widget.
references = cmds.file(q=True, reference=True)
return references

def run(self, store):
'''
Add selected reference to the store
'''
try:
selected_reference = self.options['selected_reference']
except Exception as error:
raise PluginExecutionError(f"Provide selected_reference: {error}")

self.logger.debug(f"Reference {selected_reference}, has been collected.")

try:
# Get shortname of the reference
short_name = cmds.referenceQuery(selected_reference, shn=True)
store['reference_name'] = short_name
if self.options.get("collect_path"):
# Get the file path of the reference
file_path = cmds.referenceQuery(selected_reference, filename=True)
store['reference_path'] = file_path
except Exception as error:
raise PluginExecutionError(f"Error rised when trying to query name and filepath of {selected_reference}: {error}")