Toon Boom Harmony 14.0
Scripting GuideLegal Notices
Toon Boom Animation Inc.
4200 Saint-Laurent, Suite 1020
Montreal, Quebec, Canada
H2W 2R2
Tel: +1 514 278 8666
Fax: +1 514 278 2666
toonboom.com
Disclaimer
The content of this guide is covered by a specific limited warranty and exclusions and limit of liability under theapplicable License Agreement as supplemented by the special terms and conditions for Adobe®Flash® File
Format (SWF). For details, refer to the License Agreement and to those special terms and conditions.
The content of this guide is the property of Toon Boom Animation Inc. and is copyrighted.
Any reproduction in whole or in part is strictly prohibited.
Trademarks
Harmony is a trademark of Toon Boom Animation Inc.
Publication Date
9/12/2019
Copyright © 2017 Toon Boom Animation Inc., a Corus Entertainment Inc. company. All rights reserved.

2

Harmony 14 Scripting Guide

Contents
Toon Boom Harmony 14.0 Scripting Guide

1

Contents

3

Chapter 1: About Scripting

4

Detailed Scripting Method

4Move from QSA to QT Script

4

About Scripts

5

Creating Qt Scripts

6

Deleting Qt Scripts

11

Troubleshooting Script Errors

12

Using External Script Editors

13

Importing Scripts

15

Linking Scripts to Buttons

173

Chapter 1: About Scripting

Chapter 1: About Scripting
The Harmony Scripting guide contains information which helps you to understand how to use Qt Script, thescripting language supported by Toon Boom Harmony.

Detailed Scripting Method
For details about the scripting nodes, methods, and DbScript documentation, click the links below.
lHarmony Script Interface DocumentationlScript Module DocumentationlDbScript Documentation

You can also find the help files in the Script Editor view. From the Script Editor menu, select Help > ScriptingInterface Documentation.

Move from QSA to QT Script
As of Toon Boom Harmony 10.3, Toon Boom Animation has changed the scripting language. The scripting
language has changed to Qt Script from QSA for a better and faster scripting environment than before. Script
storage is now done as plain text, *.js instead of *.qsa format.
This change to the API improves the software and supports 64-bit platforms. As always, we have made every
effort to enable backward compatibility between this version and earlier versions which used QSA script.
•Simple functions should port seamlessly.

•Class definitions must follow the new QT Script syntax, so existing scripts may be modified.

NOTE:Detailed instructions on moving QSA script to Qt Script can be found in the "Moving from QSA to Qt Script"
documentation at this link: qt-project.org/doc/qt-4.8/porting-qsa.html
For a general overview of the QT UI toolkit, refer to qt-project.org/doc/qt-4.8/index.html
For a tutorial on coding in JavaScript, refer to https://www.w3schools.com/js4

Harmony 14 Scripting GuideAbout Scripts
Qt Script provides access to many of the functions supported in the Harmony interface. With Qt Script, you canautomate a number of Harmony functions to speed up the completion of various repetitive tasks.
Qt Script is an object-oriented scripting language based on the ECMAScript standard, like JavaScript and JScript.
However, there are some differences that distinguish Qt Script from these other scripting languages, which arefamiliar to web programmers.
To use scripts prepared by other users, you must import those scripts. You can add buttons to the Scripting toolbar
for quick and easy access.

5Creating Qt ScriptsCreating Qt Scripts
Using the Script Editor, you can create Qt scripts for Harmony.
For details about the scripting nodes, methods, and DbScript documentation, click the links below.
lHarmony Script Interface DocumentationlScript Module Documentationl

DbScript Documentation

You can also find the help files in the Script Editor view. From the Script Editor menu, select Help > ScriptingInterface Documentation.
When you create a new scene, the TB_sceneCreated script automatically sets the scene length to 60 frames
and adds one of each of the following nodes: drawing element, composite, display and write.
You can find the script in the Script Editor window.

You can customize this script to fit your current project needs. This way, you can set the default scene length to
any number of frames you want, or even decide which types of elements and nodes you want to be in your scene
when you create it.
How to create a script
1. From the top menu, select Windows > Script Editor.
The Script Editor view opens listing all the available JavaScript files.

6Harmony 14 Scripting Guide

2. Do one o the folowing:lFrom the Script Editor menu, select File > New Scriptl

In the Script Editor toolbar, click the New Scriptl

From the top menu, select Windows > Toolbars > Script Editor.

button.

The New Script dialog box appears.

3. Enter a name and click on OK.
lWhen working with Harmony Server, you must set the location where the script will be saved,
either User level, Global level, Environment level, or Job level.

7Creating Qt Scripts

When working with Harmony Stand Alone, your custom scripts and default scripts are stored in:lWindows:llllToon Boom Harmony Premium: C:\Users\[user_name]\AppData\Roaming\Toon BoomAnimation\Toon Boom Harmony\1400-scripts
Toon Boom Harmony Advanced: C:\Users\[user_name]\AppData\Roaming\Toon BoomAnimation\Toon Boom Advanced\1400-scripts
Toon Boom Harmony Essentials: C:\Users[\user_name]\AppData\Roaming\Toon BoomAnimation\Toon Boom Essentials\1400-scripts

Mac OS X:lllToon Boom Harmony Premium: /Users/[user_name]/Library/Preferences/Toon BoomAnimation/Toon Boom Harmony/1400-scripts
Toon Boom Harmony Advanced: /Users/[user_name]/Library/Preferences/Toon BoomAnimation/Toon Boom Advanced/1400-scripts
Toon Boom Harmony Essentials: /Users/[user_name]/Library/Preferences/Toon Boom
Animation/Toon Boom Essentials/1400-scripts

On Mac OS X, the Library folder is a hidden folder. To display the display the folder, told down the Alt key.
lLinux:l/home/[user_name]/Toon Boom Animation/Toon Boom Harmony/1400-scripts/l/home/[user_name]/Toon Boom Animation/Toon Boom StageAdvanced/1400-scripts/

When working with Harmony Server, your custom scripts are stored in:lGlobal: [Server_Name] > USA_DB > scriptslEnvironment: [Server_Name] > USA_DB > environments > [environment_name]lJob: [Server_Name] > USA_DB > jobs > [job name]lUser: [Server_Name] > USA_DB > users > [user_name] > stage > 1400-scripts
The name of your script appears in the File column of the Script Editor view.

5. Click in the right side of the Script Editor and start writing your script. Try typing in the following script:

8

Harmony 14 Scripting Guidefunction add3dPathCol(){column.add(“ColumnName”, “3DPATH”);}

NOTE:
For a tutorial on coding in JavaScript, refer to https://www.w3schools.com/js
For a detailed Harmony script interface documentation, refer to Harmony Script Interface Documentation
You can also find the help files in the Script Editor view. In the Script Editor menu, select Help > ScriptingInterface Documentation.

6. To check your syntax, click Verify.
A window opens with syntax information.

7. To test your script, select the script you want to run from the File column.
8. Do one of the following:‣From the Script Editor toolbar, click the Runbutton.

‣From the Script Editor menu, select Play/Debug > Run.

A window opens to ask you for the target function to run. In the window, select the function you want toexecute.

NOTE:To avoid selecting the function every time you want to run your script, you can set a target function. In the Script
Editor toolbar, click the Set Target
button or select Play/Debug > Set Target from the Script Editor menu.
In the Function column, select the function to target and press OK.

9Creating Qt Scripts‣To stop the execution of your script, click the Stop Execution

button.

‣You may receive this message: Only functions that have been saved or are explicitly called will beexecuted.
This usually occurs if you did not select the function you wanted to run from the File column before
running the script. When this happens, click Save and run your script again.

‣You may also see this message on the right side of the Script Editor:

This is because the software jumped to the <<Sandbox>> item in the Function column. The<<Sandbox>> is provided to test scripts without saving them. Simply click on your newly createdscript and run it again.

10Harmony 14 Scripting Guide

Deleting Qt Scripts
Use the Script Editor to delete scripts.
How to delete a script
1. In the Script Editor, in the File column, select the script to delete.
2. Do one of the following:l

From the Script Editor toolbar, click the Delete Scriptl

From the Script Editor view menu, select File > Delete Script.

11button.

Troubleshooting Script Errors

Troubleshooting Script Errors
Use the Debug command in the Script Editor to find all the errors in a script.
How to troubleshoot errors in your script
1. In the File list, select the script containing the function to debug.
2. Do one of the following:l

From the Script Editor toolbar, click the Debug

button.

l

From the Script Editor menu, select Play/Debug > Debug.

A window opens listing the scripts and functions available.

3. In the Functions column, select the function to debug and click OK.
The Qt Script Debugger opens.

12Harmony 14 Scripting Guide

Using External Script Editors
If you are more comfortable editing your scripts using another editor, Harmony allows you to set an external script
editor and use that one instead.

NOTE:
If you do not set an external editor, on Windows and Mac OS X, when selecting the External Editor option, it will
launch the registered editor for JavaScript program (e.g. Visual Studio, XCode or Brackets).
Multiple files can be opened in the same editor instead of starting a different copy of the editor each time a*.js script is selected.

How to set an external editor
1. Do one of the following:l

From the Script Editor menu, select Editor > Set External Editor.

l

In the Script Editor toolbar, click the Set External Editor

button.

The Set External Editor window opens.

2. In the external editor, type or paste the complete path to the application, including its name and extension.
For example, if you want to set Adobe Dreamweaver as your external editor, a Windows path would look likethis:
C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS5\Dreamweaver.exe
On Mac OS X, simply specify the application name. If the application supports the Applescript OpenDocument protocol, it will open.
3. Click OK.
How to edit a script in an external editor
1. In the File list, select the script to edit.
2. Do one of the following:l

From the Script Editor menu, select Editor > External Editor.

l

In the Script Editor toolbar, click the External Editor

button.

3. In the external editor that opens, edit the script and save the file.

13

Using External Script Editors

4. In Harmony, refresh the Script Editor view by selecting another script and then selecting your edited script
again to see the modifications.

14Harmony 14 Scripting Guide

Importing Scripts
To use scripts prepared by other users, transfer the *.js files from the computer where the scripts were created tothe one that you intend to use. Then use the Script Editor to import the *.js files from where they are saved on yourcomputer.
When working with Harmony Stand Alone, scripts that you created while working on a scene or imported areavailable for all other projects created on the same computer; there's no need for any kind of transfer or import. Youcan find your custom, default and imported scripts in:lWindows:llll

Toon Boom Harmony Premium: C:\Users\[user_name]\AppData\Roaming\Toon Boom Animation\Toon Boom Harmony\1400-scripts
Toon Boom Harmony Advanced: C:\Users\[user_name]\AppData\Roaming\Toon BoomAnimation\Toon Boom Advanced\1400-scripts
Toon Boom Harmony Essentials: C:\Users[\user_name]\AppData\Roaming\Toon BoomAnimation\Toon Boom Essentials\1400-scripts

Mac OS X:lllToon Boom Harmony Premium: /Users/[user_name]/Library/Preferences/Toon Boom Animation/Toon Boom Harmony/1400-scripts
Toon Boom Harmony Advanced: /Users/[user_name]/Library/Preferences/Toon Boom Animation/Toon Boom Advanced/1400-scripts
Toon Boom Harmony Essentials: /Users/[user_name]/Library/Preferences/Toon Boom Animation/Toon Boom Essentials/1400-scripts

On Mac OS X, the Library folder is a hidden folder. To display the display the folder, told down the Alt key.
lLinux:l/home/[user_name]/Toon Boom Animation/Toon Boom Harmony/1400-scripts/l/home/[user_name]/Toon Boom Animation/Toon Boom StageAdvanced/1400-scripts/

With Harmony Server, scripts that you have been working on and imported are available at the level you savedthem:lGlobal: [Server_Name] > USA_DB > scriptslEnvironment: [Server_Name] > USA_DB > environments > [environment_name]lJob: [Server_Name] > USA_DB > jobs > [job name]lUser: [Server_Name] > USA_DB > users > [user_name] > stage > 1400-scripts

If you deleted default scripts and would like to reload them, you can find them in:15

Importing ScriptslWindows: Program Files (x86)> Toon Boom Animation > Harmony 14 [edition] > resources > scriptsl

Mac OS X: Applications > Harmony 14 [edition] > tba > resources > scriptslLinux: /usr/local/ToonBoomAnimation/harmony_14/resources/scripts

How to import scripts
1. Copy the *.js files that you want to transfer onto a USB key, or use the transfer method of your choice.
2. Transfer and save the *.js files onto the computer that you intend to use. Be sure to save them in a
logical location. You can save them directly in the default locations indicated above, in which case theywill automatically appear in the Script Editor. If you prefer not to mix them up with the default scripts, savethem to a different location and continue with the following steps.
l

To save time, you can copy all the files and icons located in the user preferences and pastethem back in your own preferences to avoid having to import all scripts one by one.

3. In Harmony, open a new or existing scene.
4. Do one of the following:l

In the Script Editor view, click the Import Scripts

button.

l

From the Script Editor menu, select File > Import Script.

With Harmony Server, a window opens in which you can browse to the location on the server where the*.js files are saved. You can choose the User, Global, Environment, or Job folder.
5. Select the *.js file and click Open.
When working with Harmony Server, you must set the location where the script will be saved: User level,
Global level, Environment level, or Job level.

The script is imported and appears in the Files list of the Script Editor.

16

Harmony 14 Scripting GuideLinking Scripts to Buttons
You can add buttons to the Scripting toolbar so you can access them easily. They will appear to the right of thedefault Scripting toolbar buttons.
How to link a script to a toolbar button
1. In the Scripting toolbar, click the Manage Scripts

button.

The Scripts Manager dialog box opens and displays the available scripts.

2. In the Files list, select the JavaScript file containing the function you want to add to the toolbar.
3. In the Functions list, select the function to add to the toolbar.
4. Click the Right Arrowbutton to add the function to the In Toolbar list.

5. To load a custom icon, click Customize Icon and browser for a *.png, *.jpg or *.xpm file.
6. To customize the tooltip appearing in the Scripting toolbar, click Customize Tooltip and type in the new tooltip in the Function Tooltip window.

17Linking Scripts to Buttons

7. Click OK.
How to execute a script
1. Once the script is added to the Scripting toolbar, you can press on the corresponding script button toexecute the action—see How to link a script to a toolbar button on page 17.
2. You can press the Esc key to interrupt the execution of a script.

18