Page 1 of 1

Interacting with QCAD

Posted: Fri Oct 06, 2017 11:16 am
by andrew
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?

Re: Interacting with QCAD

Posted: Fri Oct 06, 2017 11:46 am
by andrew
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.