Share

Python Hooks Reference

What are the Python Hooks

Python Hooks in Flame are place where external Python code can be injected to monitor, inspect, or change the behaviour of the application. They are meant to help you integrate Flame into a shot management system, monitor archives, or just specify how Batch setups are named as examples.

All Python hook files are located in /opt/Autodesk/<application>/python/.

To provide more flexibility in how hook implementations are deployed, Flame loads modules, searching for supported methods until all supported hooks are found. This allows you to separate hook implementations into multiple files, making allowance for better organization.

Note: The hooks parameters and usage are documented within the Python files located in /opt/Autodesk/<application>/python/. Samples and example files are located in /opt/Autodesk/<application>/python_examples/.
Note: Hooks are blocking, and relinquish control only once they complete. To run a hook in its own thread, see Threading Hooks.



Hooks Location

User, Project, and Application, and Shared locations

You can assign python hooks to a given user or project. Simply add the Python file with the custom hooks in one of the following locations:

  • A specific user:

    • Linux: /home/<user name>/flame/python
    • macOS: /Users/<user name>/Library/Preferences/Autodesk/flame/python
  • A specific project: /opt/Autodesk/project/<project name>/python

    • In the future, any python files located there will be copied with the project when the project is converted to a new version.
  • A specific application version: /opt/Autodesk/<PRODUCT>_<VERSION>/python

  • A global, opened and shared location: /opt/Autodesk/shared/python

    • Will be used by all users and projects in all versions.

Other locations

It is possible to make Flame scan a directory other than /opt/Autodesk/<PRODUCT>_<VERSION>/python for .py files by setting the DL_PYTHON_HOOK_PATH environment variable to the desired path.

Multiple paths can also be used by separating them by :.

Naming

Python does not support having two files of the same name. Make sure that files have unique names if they are in more than one location.

Some hooks support multiple definitions.

  • For hooks that do not return any values, every hook will be called once when the hook point is reached.
  • For hooks that returns values. The way to handle multiple definitions might vary but this will usually result in the union of the return values.



Third Party Packages

In order to avoid disruption with the system Python installation, Flame provides its own distribution of Python located in /opt/Autodesk/python/<VERSION>/.

Third party site-packages can be installed in it. Pip can be used to do so using /opt/Autodesk/python/<VERSION>/bin/pip.

Was this information helpful?