Page 1 of 1

Old School Command Scripting

Posted: Thu Nov 06, 2025 1:56 pm
by HJ Seef
The Command line entry is always handy for a draftsman.

QCAD/CAM 3.32.4 / Qt 5.14.2 / Linux x86_64
Command: new
Command: line
Coordinate: 0,0
Coordinate: 0,210
Coordinate: 210,297
Coordinate: 0,297


Fidling around I tried the old school Command scripting.

Example; a file A4.scr contains the text: line 0,0 210,0 210,297 c
where every space is an [Enter].
This has always worked fine (and still does in AutoCad).


Executing the script I use; Command: runscript A4 [Enter]

result; QCAD/CAM 3.32.4 / Qt 5.14.2 / Linux x86_64
Command: new
Unknown command or invalid coordinate or value: "runscript a4.scr"
Numbers may be entered as: "3.142"
Coordinates may be entered as: "1.234,1.234" (absolute) or "@1.234,1.234" (relative) or "10<278.873" (polar)
or "@10<278.873" (relative polar)
You may change the number / coordinate format in the application preferences.
Unknown command or invalid coordinate or value: "run script a4"
Unknown command or invalid coordinate or value: "rscript a4"
Unknown command or invalid coordinate or value: "script a4"
Unknown command or invalid coordinate or value: "runscript a4"
Command: runscript
Script exception in script '/home/all/QCAD/Scripts/A4.scr': SyntaxError: Parse error


Renamed the script as A4.js.

Result;QCAD/CAM 3.32.4 / Qt 5.14.2 / Linux x86_64
Command: new
Unknown command or invalid coordinate or value: "runscript a4"
Unknown command or invalid coordinate or value: "run script a4"
Unknown command or invalid coordinate or value: "rscript a4"
Command: runscript
Script exception in script '/home/all/QCAD/Scripts/A4.js': SyntaxError: Parse error


Where is what going wrong?

Re: Old School Command Scripting

Posted: Thu Nov 06, 2025 3:08 pm
by CVH
Hi,

Scripting under QCAD uses scripts written in ECMAScript (JavaScript) based on the QCAD API.
Most QCAD tools are created as such.

There is also a simple API, see here.
Select and copy all and save that as a JS script with a plain text editor, suffix is *.js

Code: Select all

include("scripts/simple.js");
addLine(0,0,210,0);
addLine(210,0,210,297);
Then execute the script with Misc .. Development .. Run Script (XC) or use the runscript command.
These 2 lines are generated in the current drawing, on the current active layer using default attributes or General Properties.
Scripts use a dot as decimal separator and a comma as list separator.


The QCAD Command Line is mostly intended to enter a list of coordinates.
It is not specialized in understanding a list of instructions or macro's.
It might work up to a certain point. QQ or reset would be the instruction to terminate a tool, all tools.
It doesn't executes scripts itself, the standard QCAD tool XC is intended for that.

Start the 'Line from 2 Points' tool:
> line ENTER
Now enter a list of coordinates, select and copy all and paste that in the QCAD Command Line:

Code: Select all

0,0
210,0
210,297
After the first point the line tool automatically continues starting from the former given or indicated coordinate, the Relative Zero.
But it can get more complicated to use other tools this way.
Coordinates can be given as absolute, relative, polar or relative polar.
Example given for a dot as decimal separator and a comma as list separator.
These are by Application Preferences.


Another solution would be a macro handled by Draw From CSV.
This can be prepared in a spreadsheet and has several more possibilities.
Especially intended for values depending on math, parametric relations and so on.
Typically there is an export sheet that collects all data into CSV instructions intended for QCAD.

Regards,
CVH

Re: Old School Command Scripting

Posted: Wed Nov 12, 2025 9:43 am
by HJ Seef
@CVH OK, that's a comprehensive answer. I already knew most of the information; see also HPPenplotter.js.


My question was about the capabilities of the Command Line Interface (CLI) itself, and whether it's capable of processing .scr files.

=> "The QCAD Command Line is mostly intended to enter a list of coordinates."

This remark actually gives the answer. So, under QCAD, the CLI is no longer a CLI, but (like the dysfunctional appendix), a vestigial appendage. And that's a shame.



Perhaps someone is now wondering what a CLI and a CLI-script is. Imagine a CAD program before the invention of the mouse. The screen only shows the drawing, and at the bottom a line of text with the prompt Command: . The keyboard consists of a wired ASCII letter block, supplemented with a keypad block, and there are also 8 special keys which can be used to start a pre-programmed program function (hence the name 'function keys').

Back then, CAD drafters had to enter all commands as text on the Command Line, such as Line, Circle, Move, etc. With the keypad in cursor mode, the right hand is used to operate the crosshairs via the keypad keys. Entering numbers via the top row of keys was ingrained in my brain back then.

AutoCAD started once as a newly developed version of an Unix CAD application. With a special memory bank (Hercules card), the screen of an accounting machine (the PC!) could be used for a CAD application (or as an Arcade machine).

Because DOS is a Real-Time Operating System with hardware keyboard input buffers, a skilled drafter can enter commands faster than the graphics card can process changes. Because the graphics display has no feedback whatsoever (no waiting for any button to appear), you can draw very fast. For quickly working out a design, I still use AutoCAD 10 under DOS.



The major big advantage of a full functional CLI is that the SCRIPT-command, starts simulate manual input from an ASCII file. Any user without any programming knowledge at all, can automate a drawing action this way. Even today's AutoCAD can use a .scr file as an intermediate link between any database or spreadsheet program, or any programming language like BASIC, C, or whatever.

Sorry, QCAD's CSV-input is not a serious option, and ECMAScript is not a simple scripting/batch language but a complex quirky programming language; not exactly an entry-level program for the novice programmer. If the CLI is made full functional again, it would make QCAD far more versatile.


For more information about CLI-scripting, an attachment about .scr files is included.

Re: Old School Command Scripting

Posted: Fri Nov 14, 2025 3:15 pm
by CVH
Sorry to hear that you dismiss Draw From CSV as not a serious option.
It was specifically written to overcome the shortcomings of the Command Line interpreter.
What can be achieved with this tool defies even my initial imagination.

A CSV with drawing instructions is the intermediate link as you specified, the source is not limited to a spreadsheet program.
I could have opted for instructions in some XML format or in the JSON format but those are even more obscure for a human.
The drawing is also created as a whole in the background, screen rendering starts when execution ends.

I had none and still have no reference of the full .scr or CLI script format used by AutoCAD.
It would not be that hard to create a similar basic interpreter based on the JS code that is already part of DCSV.
This requires an in-depth knowledge of all ACAD instructions and most probably there is no simple QCAD analog for everything.
Basic ... It would not support all forms of LISP utilities that may be out there.

The QCAD API is what it is. QCAD is based on Qt and has used ECMAScript since it was created.
Somehow, things have to be translated into how the API defines it.
All common drawing tools, such as Line from 2 Points (LI), do nothing else.


You can always enter a new feature request in QCAD Bugtracker.
Nothing guarantees that the CLI will be rewritten and that some well established functionalities are dropped.

Also note that:
  • 'QCAD is never intended to be yet another ACAD clone.'
    'When comparing QCAD to other CAD systems, please consider the platform availability and license cost as well for a fair assessment.'

Regards,
CVH