You can download sample Actions from our Action repository on Bitbucket. You can also visit the Actions sections on our ftrack community forum.
Lets implement an Action that takes a selection, write out the name of the selection in a HTML file and attach the file to the users Job list.
First, let the Action know which server to contact, which API key to use and a valid ftrack username.
Note: this can be setup in many different ways, but for simplicity to get started with the script we’re adding it to to the file instead of a global environment setting.
Next, create a Class that inherits ftrack.Action. Also specify a label and a unique identifier that will be used later on.
The function discover() gets invoked when a user tries to bring up the Action menu to list available Actions. You can override the discover() function in your class that inherits ftrack.Action. By doing so you have control on where your action gets invoked (Context, Selection mode or User permissions for example). In this example we’re restricting our selfs to a single selection, and the Action will not be visible if the selection is a User ()that we are not allowed to invoke this action if we clicked on a User. We’re also specifying an icon. If you don’t, the system will render a default icon for you based in the initials in your label.
Launch is invoked when a user click on your Action. Here we can return a UI to request more information from the user. Read more about UI for Actions. In this example we are requesting a color selection from the user. If no color selection is provided, the default will be returned, which is currently set to green (‘value’ : ‘green’). If When we’ve got input from the user we can call doSomething() with the values from the UI and do the actual action. In a production environment you would probably want to thread this so that multiple user can use the Action at the same time. Please see code examples of this in our Actions code repository (decorator async). This will be part of the framework in the future.
The only thing that doSomething() does right now is to add a record to the users job list, set it to “done”, and set the description to the color that was passed from the UI. As you can it’s easy to integrate with the built in Job list, just call ftrack.createJob() with the user id of the user running the Action (or another user id if you want to add it to another users job list), a description and current status of the job.
Lets make it a bit more interesting by also creating a html file, and add it as a attachment to the record in the users job list. I’m uploading the file with Job.createAttachment()
This is the final code. Follow the install instructions above to have it running on your machine.