Download the example extensions
Framework Standalone Examples
This recipe will guide you on how to run and interact with the framework in a standalone environment, with or without UI. We will also cover how to programatically interact with the framework from inside a DCC.
Index:
- Preparation
- Initialising the framework
- Initialise UI Standalone
- Initialise UI in DCC
- Run tool config by command line
- (Advanced) Manipulating tool config by command line
Preparation
- Create virtual environment or install the following libraries in your PYTHONPATH
pip install ftrack-framework-core
pip install ftrack-python-api
- Optional libraries:
pip install ftrack-constants
pip install ftrack-utils
pip install ftrack-framework-core
pip install ftrack-framework-qt
pip install ftrack-qt
pip install ftrack-qt-style
- If you want to do it in a standalone interpreter, just run python on your terminal and jump to Initialising the framework section.
- In a DCC (Maya example):
- Start maya and set your PYTHONPATH to your environment site-packages
- If you have installed the libraries in a separated python environment, make sure they are available inside your interpreter
import sys
sys.path.append('<path_to_your_custom_environment>/lib/python3.7/site-packages')
if trying this in an old Maya version(Min.Supported version 2022) and you have a crash when raising the UI, double check that you have an updated certifi. If you have installed the mentioned libraries above in a clean environment, then you can point the certifi using:
os.environ['REQUESTS_CA_BUNDLE'] = '<you_virtual_environment>/lib/python3.7/site-packages/certifi/cacert.pem'
os.environ['WEBSOCKET_CLIENT_CA_BUNDLE'] = '<you_virtual_environment>/lib/python3.7/site-packages/certifi/cacert.pem'
os.environ['SSL_CERT_FILE'] = '<you_virtual_environment>/lib/python3.7/site-packages/certifi/cacert.pem'
Initialising the framework
- You can use extensions provided in any integration as starting point. Or you can download them from here.
- Make sure that any extension requirements are installed on your python path . (Fex: PySide). In the provided extensions example, remove Maya extensions folder if you are not in Maya, as it might fail on discovering them for the missing maya library.
import os
import ftrack_api
from ftrack_framework_core import host, event, registry
import ftrack_constants.framework as constants
# Set ftrack environment variables
os.environ['FTRACK_SERVER'] = 'https://your.ftrack.server' os.environ['FTRACK_API_USER'] = 'your_username'
os.environ['FTRACK_API_KEY'] = 'your_api_key'
# Initialize session and event manager
session = ftrack_api.Session(auto_connect_event_hub=False)
event_manager = event.EventManager(
session=session, mode=constants.event.LOCAL_EVENT_MODE
)
# SET YOUR DESIRED STARTING CONTEXT ID
os.environ['FTRACK_CONTEXTID'] = '<your_context_id>'
# SET THE PATHS WHERE YOUR FRAMEWORK EXTENSIONS ARE FOUND
FTRACK_FRAMEWORK_EXTENSIONS_PATH = [
'<the_path_to_your_extensions_folder>'
]
# Initialize registry and register extensions
registry_instance = registry.Registry()
registry_instance.scan_extensions(paths=FTRACK_FRAMEWORK_EXTENSIONS_PATH)
# Initialize Host
host_instance = host.Host(event_manager, registry=registry_instance)
# Initialize Client
from ftrack_framework_core import client
client_instance = client.Client(event_manager, registry=registry_instance)
Initialise UI Standalone:
import sys
# Import PySide
try:
from PySide6 import QtWidgets
except ImportError:
from PySide2 import QtWidgets
# Init PySide QApplication
app = QtWidgets.QApplication.instance()
if not app:
app = QtWidgets.QApplication(sys.argv)
# Run tool
client_instance.run_tool(
name='publisher'
dialog_name='framework_standard_publisher_dialog',
options={'tool_configs': ['standalone-file-publisher']},
)
sys.exit(app.exec_())
Initialise UI in DCC:
# Get your DCC config from the registry if it exists (If not you can manually fill the arguments as in the standalone example)
dcc_config = registry_instance.get_one(
name='framework-maya', extension_type='dcc_config'
)['extension']
# Pick a tool from the DCC_config
choosen_tool = None
for _tool in dcc_config['tools']:
if _tool.get('name') == 'publish':
choosen_tool = _tool
if not choosen_tool:
choosen_tool = dcc_config['tools'][0]
# Run the tool
client_instance.run_tool(
name=choosen_tool['name'],
dialog_name=choosen_tool['dialog_name'],
options=choosen_tool['options'],
)
Run tool config by command line:
You should manually modify the tool config to contain static options according to your plugin needs. For example in the provided standalone-file-publisher tool_config you should manually add the context_id, status_id, asset_name and comment in the store_asset_context plugin as well as the folder_path and file_name options in the file_collector plugin before executing the tool config.
from ftrack_utils.framework.config.tool import get_tool_config_by_name
# Get the publisher tool_config
publish_tool_config = get_tool_config_by_name(
client_instance.tool_configs['publisher'], 'standalone-file-publisher'
)
# Run tool
client_instance.run_tool(
name='publisher',
options={'tool_configs': [f'{publish_tool_config["name"]}']},
)
# Or you could run the tool config directly using:
#client_instance.run_tool_config(publish_tool_config['reference'])
(Advanced) Manipulating tool config by command line:
from ftrack_utils.framework.config.tool import (
get_tool_config_by_name,
get_plugins,
)
# Get the publisher tool_config
publish_tool_config = get_tool_config_by_name(
client_instance.tool_configs['publisher'], 'standalone-file-publisher'
)
# Get the plugins on it
publish_plugins = get_plugins(publish_tool_config)
file_collector_plugin = None
asset_context_plugin = None
for _plugin in publish_plugins:
if _plugin.get('plugin') == 'file_collector':
file_collector_plugin = _plugin
elif _plugin.get('plugin') == 'store_asset_context':
asset_context_plugin = _plugin
# Modify options of the desired plugin
client_instance.set_config_options(
tool_config_reference = publish_tool_config['reference'],
plugin_config_reference = asset_context_plugin['reference'],
plugin_options = {
'context_id': client_instance.context_id,
'asset_name':'file_test',
'comment':'This is a test from standalone',
'status_id':'44ddd0fe-4164-11df-9218-0019bb4983d8',
}
)
client_instance.set_config_options(
tool_config_reference = publish_tool_config['reference'],
plugin_config_reference = file_collector_plugin['reference'],
plugin_options = {
'folder_path':'/Users/ftrack/Downloads/homologacio_furgo',
'file_name':'IMG_6047.jpg',
}
)
# Run tool
client_instance.run_tool(
name='publisher',
options={'tool_configs': [f'{publish_tool_config["name"]}']},
)
# Or you could run the tool config directly using:
#client_instance.run_tool_config(publish_tool_config['reference'])]]