Tutorial: Script Programming

This tutorial introduces the QCAD ECMAScript interface by looking at the different possibilities to run and integrate scripts in QCAD.


QCAD comes with a very powerful and complete script interface, allowing you to access almost the entire QCAD API as well as the Qt API through ECMAScript (JavaScript).

Using Scripts in QCAD

There are various ways to run and integrate script in QCAD. Some are covered in separate tutorials:

  • The Script Shell
    This is a good starting point to experiment and do your first steps with scripting.
  • Running Scripts from a File
    Executing more complex non-interactive scripts. 
  • Running Scripts from the Terminal
    When using QCAD as part of an automated process, scripts can be executed from the terminal (command line) of an operating system.
    • With the QCAD GUI
      To start the QCAD GUI and then execute a script, use the -exec switch. This example starts QCAD and then starts the action to open a file:
      qcad -exec scripts/File/OpenFile/OpenFile.js
    • Without the QCAD GUI
      If a script does not require the QCAD GUI or creates its own GUI, use the -autostart switch instead:
      qcad -autostart myscript.js
      The script passed to QCAD through -autostart can contain any kind of script code from a simple print("Hello World"); over a command line tool to a complete GUI driven application.
  • Interactive Script Actions
    Script actions are scripts that create a menu and/or tool button and typically allow the user to interact with a drawing, for example by clicking coordinates, clicking entities or entering parameters.
  • Command Line Tool Scripts
    These scripts implement a command line tool. Command line tools are usually used to automatically process large numbers of drawings or on web servers as part of a web service.