Use available Python hooks are there to help you integrate Flame into a shot management system, monitor archives, or just specify how batch setups are named.
All Python hook files are located in /opt/Autodesk/<application>/python/. Note that every hook presented in this document is blocking, and relinquishes control only once it completes. To run a hook in its own thread, see Threading Hooks.
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. Module specific hooks are part of specific files:
Need to pass the project name between hooks? Use the appInitialized hook. This hook is called whenever the project changes. You can assign the project name passed by the hook to a global variable which can then be read by the other hooks.
globalProjectName = ""
def appInitialized( projectName):
globalProjectName == projectName
export DL_PYTHON_HOOK_PATH=/share_1/dev/python_hooks/test:/share_1/dev/python_hooks/production
A new hotkey has been added to re-scan hook files while the application is running. This is useful to iteratively test changes during implementation.
By default, this is mapped to Ctrl+Shift+P+H, but can be found in the hotkey editor under the name Scan for python hooks.
The python hooks described above block the application until they finish their task. To get around this, you can run a hook in its own thread. The example below provides you with the code required to run renderEnded() in a thread separate thread. Comments have been added inline.
from threading import Thread
import atexit
#threads is a list used to keep track of all the threads created
threads = []
def wait_for_threads_at_exit():
global threads
if (len(threads) > 0 ):
for thread in threads:
print("Waiting for %s" % thread.name)
#join() waits for the thread to finish before relinquishing control,
# making sure everything is done before exit.
thread.join()
threads = []
#Clean up by Python on exit
atexit.register(wait_for_threads_at_exit)
#The actual code to execute in a thread.
def async_callback(param1, param2):
print("async_callback(%s, %s)\n" % ( str(param1), str(param2)) )
#renderEnded is the actual hook called by the application,
# with its standard moduleName, sequenceName, and elapsedTimeInSeconds
# parameters.
def renderEnded(moduleName, sequenceName, elapsedTimeInSeconds):
#Creates the separate thread
thread = Thread( target = async_callback,
name = "async callback",
args = ( moduleName, sequenceName, ) )
thread.start()
#Add to threads[] the just created thread, to keep track and
# clean up on exit.
threads.append( thread )
The user always has access to export hooks in the contextual menu for Shared Libraries, lock or no lock. But if the shared library is locked when the export hook is called, and if the preset selected by the user re-imports the exported material, and the source clip is in the library, the re-import silently fails.
Starting in the 2017 extension 1 version of the Creative Finishing applications, libwiretapPythonClientAPI.so is now located in /opt/Autodesk/python/<VERSION>/lib/python<PYTHON_VERSION>/site-packages/adsk/. This ensures it is in the right folder for Wiretap calls to be made by the Python hooks.
Note that there is also a symlink in /opt/Autodesk/<PRODUCT>_<VERSION>/python/ to libwiretapPythonClientAPI.so. That way, everything that was working previously should still work.
However you should update your Python hooks to use the site-package libwiretapPythonClientAPI. You can do this by replacing import libwiretapPythonClientAPI with from adsk import libwiretapPythonClientAPI.