Bernard Engine · Doc

Scripts and Python API

Bernard can be automated in two ways:

Scripts and the API are meant for TDs and pipeline developers. An artist does not need them to work.

What scripts can do

Through the API, a script can:

A script acts with the permissions of the signed-in user. A write refused by the rules (state machine, permissions) does not raise an error: the call returns False. See Workflows, states and templates for these rules.

Script tasks

A script task is a workflow task that launches a command. The script thus becomes a step of the workflow, with its sources, its successors and its states.

What it carries:

Property Role
Command the command to launch; it is an expression, which can read the properties of the task, the item, the project…
Launch On the workstation that runs the script
Task Priority the order in the queue (from 1 to 99, the highest goes first)
Log the output of the script
Files the files of the task

How it runs:

  1. When the task becomes Ready (its sources are finished), the Bernard on the designated workstation launches it. There is no Run button: to run a script again, set its task back to Ready.
  2. It goes to WIP and its output (normal and errors) is written to Log. While it runs, the Log is updated every 5 seconds.
  3. It goes to Done if the script ends with code 0, to Failed otherwise.

Rules to know:

Actions, triggers and events

The Python API

Reference

The complete reference, generated from the code and kept up to date with every version, is online:

bernardengineapi.readthedocs.io

There you will find the CallBernard class (communicating with Bernard), tools for paths and third-party software (3DEqualizer, Nuke…) and the constants to use with the API. For each method: what it does, what it accepts, what it returns and the errors it reports. The application opens this reference from Help › API Documentation.

Connecting

The API talks to the Bernard client open on the same workstation, like a content creation software plugin (see DCC integrations).

from Bernard import CallBernard
from Bernard.Static import State, ClassName

bernard = CallBernard()
print(bernard.GetCurrentUserID())

Examples

The examples use made-up identifiers.

# My tasks to do, and set the first one to WIP
for task_id in bernard.GetMyTasks():
    print(bernard.GetPropertyValue(task_id, "Name"))

task_id = bernard.GetMyTasks()[0]
if not bernard.SetPropertyValue(task_id, "State", State.wip):
    print("refused: assignment, checklist, active fix…")
# Publish a new version of a file and get its path on this workstation
bernard.IncrementVersion(file_id)
print(bernard.GetPathValue(nodeID=file_id))
# The shots of a sequence that have a task in progress
shots = bernard.FindNodeIDs(parentIDs=[sequence_id], classNames=[ClassName.projectItem],
                            projectItemModelName="Shot")
wip = bernard.FindNodeIDs(parentIDs=[sequence_id], classNames=[ClassName.task],
                          propertyFilter={"State": [State.wip, State.pause]})
# Open a file in the studio player
bernard.OpenInPlayer(nodeID=file_id)

Method families

Need Methods (examples)
Navigating the tree GetRootID, GetParentID, GetProjectID, GetIdFromBernardPath
Searching FindNodeIDs, GetMyTasks, HasProperty, HasTags
Reading and writing properties GetPropertyValue, SetPropertyValue, GetPropertiesValues, SetPropertiesValues
Workflows and tasks GetCurrentTaskIDs, GetItemTasks, CreateWorkflowTasks, ExportWorkflowTasks
Files, paths and versions GetPathValue, SetPathValue, IncrementVersion, CreateFiles, UpdateFileThumbnail
Copying, moving, uploading, downloading FileOperation, FileOperationFromPath
Creating and deleting CreateNode, DeleteNodes, CreateUsers
Instructions and time spent GetTaskInstructions, SetInstructionChecked, GetTimeLog, SetTimeLog
Users and settings GetCurrentUserID, GetAllUsers, GetSettingsAttributeValue
Applications GetAppPathByExtension, GetAppPathsByExtension
Interface and player OpenInPlayer, BringToForeground, showMSGWindow, PopUpFileDialog

The complete list and the parameters are in the online reference.

What is new in the API in 2.1.48

Studio automation examples

These examples show what studios have automated with the API. They are scripts specific to studios, not product features. They are described here without any studio or project name, to illustrate the possibilities.

Need What the script does Launch
Reconcile quotes, deliveries and production compares a quote table, the metadata of the delivered files and the Bernard data, shows the differences, lets you choose the right value and fixes it action on a group of shots
File a delivery without typing finds the image sequence of a shot, reads its metadata, fills in the shot, copies the images into the plate file as a new version script task of the shot
Quality gate before validation refuses an incomplete delivery (missing frames, resolution, expected layers) by writing a report in the Log; the task goes to Failed on error script task before the validation
Render and convert without opening the software finds the application by the file extension, computes the path through the expression, files the render in the right version script task
Build workflows with code describes a workflow in JSON and applies it, first as a dry run to see what would be done command line
Connect other tools publishes a preview to a third-party tracking tool, warns by email when people have not arrived script task or scheduled task

Principles these examples illustrate:

Going further