Interacting with QCAD

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Interacting with QCAD

Post by andrew » Fri Oct 06, 2017 11:16 am

From a QCAD user:
How can I interact from my C#, Java, VisualBasic or other application with QCAD, for example to programmatically create drawings or interact with drawings?

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Interacting with QCAD

Post by andrew » Fri Oct 06, 2017 11:46 am

QCAD is developed in C++ with the cross platform toolkit Qt.

There are several possible ways to interact with QCAD, depending on your exact needs:

Through a Script Using the QCAD GUI
Your application could generate a JavaScript script and call QCAD to execute it. If QCAD is not running, it is launched (with user interface and all) and the script is then executed. If QCAD is already running, the script is executed. If the script adds for example a line, that line is added to the current document shown in the QCAD user interface.

Code: Select all

qcad -exec myscript.js
Through a Command Line Script (no GUI)
Since you'll probably not want to show the QCAD user interface to the user, or your application might be running on a server without a GUI, you might want to create a command line tool instead. A command line tool is essentially a script that is executed instead of launching the QCAD application:

Code: Select all

qcad -autostart myscript.js
QCAD already comes with several such command line tools, one of them is available as open source / example at:
https://github.com/qcad/qcad/tree/maste ... rawings.js
The bash file (Unices, macOS) that calls the script is:
https://github.com/qcad/qcad/blob/master/merge
And the batch file (Windows):
https://github.com/qcad/qcad/blob/master/merge.bat

Another example using the QCAD Simple API:
https://github.com/qcad/qcad/blob/maste ... drawing.js

QCAD Simple API Reference:
https://www.qcad.org/doc/qcad/latest/de ... imple.html

To check for errors under Windows, stream stderr to a file:

Code: Select all

qcad -autostart myscript.js 2>log
cat log
Through DXF
Your application could create a DXF file and pass that on to QCAD to load it, convert it, etc.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”