Open Source 2D CAD
Once you start developing your own script based QCAD tools, you might want to add them to a custom menu or tool bar, so they can be launched in a user friendly and consistent way. These instructions show how menus and tool bars are handled in the ECMAScript structure that comes with QCAD.
If you are not planning to integrate your scripts with the ECMAScripts that come with the QCAD Application, you can of course also use the standard Qt mechanisms (QMenu, QToolBar, QAction) to achieve the same.
The folder structure should now look as shown below:
The file "MyScripts.js" defines the base class for all scripts that will be placed in this hierarchy. It also defines the top-level menu title and tool bar name. All actions inside our 'MyScripts' folder are derrived from class 'MyScripts' and use functionality of this base class to define in which menu / tool bar they are shown. For this example, we want the menu to be labeled "My Scripts". Here's the complete code for 'MyScripts.js':
Behind each entry in an application menu and each button in a tool bar, is an action class that implements the behavior of the action. All actions in our example menu structure are derived from the base class
In the folder "MyAction" create a new file called "MyAction.js" with the following contents:
If you start QCAD, you will now see the new top level menu named My Scripts with the entry My Action as well as a new tool bar with one tool button.
The action, when started, writes "MyAction() is running..." to the QCAD console and then terminates itself.