You can create some custom use Python hook files to do some custom scripting.
In order to find the hook files the file name must match exactly. Please see list below.
The example scripts can be found here:
https://github.com/das-element/resources/tree/main/scripts/hooks/examples
Script | Description |
---|---|
| Gets executed before each transcoding task |
| Gets executed after each transcoding task |
| Gets executed before the file paths get loaded into the ingest view |
| Gets execture before the library elements get exported |
The software follows this order looking for Python Hook files.
directory defined in the
...
$DASELEMENT_HOOKS
environment variabledirectory defined in the
$DASELEMENT_RESOURCES/scripts/hooks
environment variableyour local
.das-element
folder (for Linux:~/.das-element/scripts/hooks
or for Windows%homepath%/.das-element/scripts/hooks
)
Info |
---|
The result data needs to be JSON serializable. |
Pre Render Hook
The input is the resolver data dictionary
which will be used to resolve the path pattern. You can modify it here before the transcoding task gets processed.
...
In the example below, in order to resolve a path pattern like <custom.dependecy>
you need to add some value for the custom data. If that is not provided the resolve would otherwise fail if you re-render the proxies and there is no main task to provide the dependency which we normally would get from the post render hook after sending the task to the render farm.
...
Link to example script:
https://github.com/das-element/resources/blob/main/scripts/hooks/examples/deadline/pre_render.py
Post Render Hook
The input is the output of the process called by the custom command task.
You will have to return a Dictionary which will be added as custom
to the resolver data and can later be accessed in the Path Builder. return {'dependency': job_id}
can later be resolved with <custom.dependency>
...
language | py |
---|
...
Link to example script:
https://github.com/das-element/resources/blob/main/scripts/hooks/examples/deadline/post_render.py
Pre Ingest Load
This hook can be used to parse the file paths to set tags and the category from the file path before the items are loaded into the ingest list. These tags and the category will automatically populate the ingest list items.
The input is a List of Dictionaries and the same has to be returned from the function.
...
language | py |
---|
...
Link to example script:
https://github.com/das-element/resources/blob/main/scripts/hooks/examples/ingest/pre_ingest_load.py
Pre Export
This hook can be used to edit, reformat or add additional values to the export from the library elements.
...
The input is a List of Dictionaries and the same has to be returned from the function.
...
language | py |
---|
...
Link to example script:
https://github.com/das-element/resources/blob/main/scripts/hooks/examples/shotgrid/pre_export.py
Troubleshooting
Logger inside python file
Since version 2.1.2
you can directly access the logger inside the hook files.
Code Block |
---|
def main(*args, logger=none):
items = args[0]
# use the Das Element logger
# will log to ~/.das-element/logs/
logger.warning('This is a warning!')
return items
if __name__ == '__main__':
main(sys.argv[1:]) |
Print inside python file
To output data to the console when customizing the hook files use a print
statement inside the main
function. The input args
will be a list of data.
To get a better idea what’s happening inside the hook files you can follow these steps:
inside the Python hook file you can add print statements
Code Block print(item) print(item['path'])
start a terminal/command prompt
activate the debug mode - set the environment variable
Code Block # Linux/MacOS export DASELEMENT_LOG_LEVEL=debug # Windows set DASELEMENT_LOG_LEVEL=debug
now run the software via the command line
Code Block # Linux /opt/das-element-1.2.1/das-element-1.2.1 # MacOS /Applications/das-element-1.2.1.app/Contents/MacOS/das-element-1.2.1 # Windows "C:\Program Files\das element\das element 1.2.1\das element 1.2.1.exe"
If you make changes to the hook file you will need to restart the application to re-read these changes
Example for pre_load_ingest.py
Code Block |
---|
import logging def main(*args, logger=none): items = args[0] result = [] for item in items: frame_range = '{}-{}'.format(item['frame_first'], item['frame_last']) sg_item = { "Version Name": item['name'], logger.warning('This is a warning!') # <- use the Das Element logger (~/.das-element/logs/) "Frame Count": item['frame_count'], "First Frame": item['frame_first'], logging.warning('This is a warning!') # <- use the default logging module "Last Frame": item['frame_last'], "Frame Rate": item['frame_rate'],for item in items: "Frame Range": frame_range, "Path to Frames": item['path'], "Tags": item['tags'].replace(',', ', '), } result.append(sg_item) return result print(item) # <- this print() will be output to the console return items if __name__ == '__main__': main(sys.argv[1:]) |
...