Introduction
In this guide, we will explain how the startup plugins work and how are they defined. We will use ftrack-framework-maya integration as example.
DCC-config
Since ftrack-framework-DCC 24.6.0 the dcc_config has the following keys:
menu
: True if you want the tool to appear on the Maya menu.run_on
:startup
is accepted to tell the framework to automatically run the defined tool as soon as the DCC starts (with or without dialog).
# Execute tool config without UI
- name: set_up_scene
run_on: startup
menu: false # True by default
options:
tool_configs:
- maya-setup-scene
In the above section of the dcc_config file, we are describing a tool named set_up_scene, that will run on the dcc startup and will not be shown in the ftrack menu. This tool will not execute any dialog but will automatically run the maya-setup-scene tool config.
Tool-config
The maya-setup-scene tool-config defined on the framework-maya 24.6.0 is very straight forward. But you can custumise it and extend it to fit your needs. Please follow any extension guide like extend_the_maya_publisher as a template.
type: tool_config
name: maya-setup-scene
config_type: setup
engine:
- maya_setup_frame_range
In the above yaml file, we are defining a tool_config, with the name maya-setup-scene, that is one of a type setup and that will execute maya_setup_frame_range plugin. The above tool config can be extended with groups, options, ui, and more plugins as much as you like, check the publisher tool-config to see a more complex tool config as reference.
Plugin
The maya_setup_frame_range plugin is the script that will be executed from the above tool-config and where the actual logic of your desired operations should go.
# :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 MayaSetupFrameRangeStartupPlugin(BasePlugin):
name = 'maya_setup_frame_range'
def run(self, store):
'''
Set the maya frame range and frame rate from the ftrack custom attributes
'''
context_id = self.context_id
task = self.session.get('Context', context_id)
if task:
try:
st_frame = task['parent']['custom_attributes'].get(
'fstart', 1.0
)
end_frame = task['parent']['custom_attributes'].get(
'fend', 100.0
)
fps = task['parent']['custom_attributes'].get('fps', 24)
# Set start end frames and frame rate
cmds.playbackOptions(
min=int(st_frame),
max=int(end_frame),
ast=int(st_frame),
aet=int(end_frame),
)
cmds.currentUnit(time=f'{int(fps)}fps')
except Exception as error:
raise PluginExecutionError(
f"Error trying to setup frame range on maya, error: {error}"
)
else:
self.logger.warning("Couldn't find a task to pick up frame range")
The above script can be customised, as desired following any of the provided customization guides like extend_the_maya_publisher. The default one picks the attributes fstrat, fend and fps from the ftrack Asset and set the values up on the Maya start and end frames as well as the frame rate. (Note that if the Asset doesn't contain those attributes the plugin will set the default values to 1-100 and 24fps )