Page 1 of 1
Automating QCAD/CAM 3 functions using scripts
Posted: Wed Jun 07, 2017 4:15 pm
by ash120
Hi
I'm looking to automate Qcad / cam by writing a script to batch process dxf files so they will be automatically toolpathed by layer, and then Gcode automatically saved for each file.
I have read your article on setting a Gcode configuration, but I wanted to see what CAM functions are available to scripts.
From the GCodeBase configuration I can see its derived from CamExporterV2 script So i 'm assuming that is where i have to look, but i cant find documentation on the functions in CamExporterV2 script.
Thanks for your help!
Re: Automating QCAD/CAM 3 functions using scripts
Posted: Fri Jun 09, 2017 2:56 pm
by andrew
All functions in CamExporterV2 are listed at:
https://www.qcad.org/doc/qcad/latest/de ... er_v2.html
CamExporterV2 exports all toolpaths in a drawing to the configured output format. It is the base class for all postprocessors.
You could create toolpaths automatically through other means than using the
CAM > Add Profile Toolpath tool. Essentially, your script would have to create a block for each tool to be used and a block for each toolpath.
Blocks for tools and toolpaths must follow a naming convention and must have certain custom properties attached.
Tool blocks are tagged with custom properties defining the:
- tool diameter
- default spindle speed
- default feedrate
- etc.
Toolpath blocks are also tagged with various custom properties:
- a copy of the properties from the tool used for the toolpath
- properties for lead in/out
- direction and side for tool radius compensation
- Z levels
- etc.
You can inspect these properties as follows:
- Enable
Edit > Application Preferences > Property Editor > Display properties of current block and current layer
- Double click a tool or toolpath block in the block list
- In the property editor, choose the
Selection "Block"
The entities inside toolpath blocks are also tagged with various custom properties to define custom properties that might vary for every entity:
- definitive feedrate
- CamNotOffset for entities that are part of a contour that is not offset (these coordinates are exported if the postprocessor uses G41/G42 for tool radius compensation)
- CamOffset for entities that are part of a calculated offset contour (these coordinates are used for simulation as well as when the postprocessor does not use G41/G42 for tool radius compensation)
- etc.
Once these blocks have been created, QCAD/CAM will automatically recognize them as tools or toolpaths. These toolpath blocks can then be exported using any available postprocessor.
Re: Automating QCAD/CAM 3 functions using scripts
Posted: Sun Jun 11, 2017 2:05 pm
by ash120
Hi Andrew,
Thanks for your reply and help with explaining the toolpath blocks, I 'll give it a go..

Re: Automating QCAD/CAM 3 functions using scripts
Posted: Mon Sep 06, 2021 8:11 pm
by raemin
The link to CamExporterV2 (
https://www.qcad.org/doc/qcad/latest/de ... er_v2.html) seems broken, any updated doc/link?
I've seen that the "CAM Legacy Export" allows to customize the XY coordinates (see "How to output scalable G-code?"
viewtopic.php?f=74&t=3962 &
viewtopic.php?t=3964) .
Code: Select all
Spesmek.prototype = new GCode();
// definition of function getXCode (note capital C in Code):
Spesmek.prototype.getXCode = function(value) {
var v = value;
if (this.getIncrementalXYZ() && !isNull(this.xPrev)) {
v -= this.xPrev;
}
return "X[" + this.formatNumber(v) + "*#<scale>]";
};
Is it possible to perform the same customization with "CAM Export" and postprocessor scripts?
Re: Automating QCAD/CAM 3 functions using scripts
Posted: Mon Sep 06, 2021 9:27 pm
by andrew
I'll see how this can be made available again.
Is it possible to perform the same customization with "CAM Export" and postprocessor scripts?
Formatting can be done while registering a variable. For example:
Code: Select all
this.registerVariable("xPosition", "X", true, "X", 4, { factor: 10, sign: true });
Parameters are:
- "xPosition": Variable name (i.e. output value of variable this.xPosition)
- "X": ID used in post processor (e.g. as "[X]")
- true: Always write even if last output was identical
- "X": String used as prefix
- 4: Number of decimal places
- {factor: 10, sign: true}: Map of formatting options:
- { sign: true|false } Force sign
- { width: number } Width of output, filled up with leading spaces or zeros
- { leadingZeroes: true|false } Force leading zeroes
- { trailingZeroes: true|false } Force trailing zeroes
- { decimalSeparator: string } Use given string instead of decimal point
- { factor: number } Apply given factor to value (e.g. 360/Math.PI/2 to convert from rad to deg)
Re: Automating QCAD/CAM 3 functions using scripts
Posted: Mon Dec 13, 2021 6:19 pm
by fertig
First of all hello everyone, this being my first post here. Iām looking into something similar, hoping to largely automate the program generation process and only leave program control in the machines own software to the operator.
I was wondering if you made progress on this and would be willing to share some details?
Also, @andrew, is there any news on the broken link to the documentation?
thanks a lot,
lukas
Re: Automating QCAD/CAM 3 functions using scripts
Posted: Mon Dec 13, 2021 9:31 pm
by andrew
First, make sure that the property editor displays properties for blocks:
Edit > Application Preferences > Widgets > Property Editor > Display properties of current block and current layer
If you now create a toolpath manually using QCAD/CAM, you can see and inspect the special tool blocks and toolpath blocks that are getting created in the process.
Tool blocks are called "CAMTOOL$$[Postprocessor]$$[Toolnumber]" and toolpath blocks "CAMTOOLPATH$$[Postprocessor]$$[Toolpath name]".
Essentially, a fully automated process would have to create one block per tool and one block per toolpath with all the various custom properties attached to make the block a tool or a toolpath:
Block representing a tool:

- Screenshot 2021-12-13 at 21.22.33.png (27.09 KiB) Viewed 15057 times
Block representing a toolpath:

- Screenshot 2021-12-13 at 21.22.44.png (52.31 KiB) Viewed 15057 times
To generate the toolpath geometry, you could then call
Code: Select all
Cam.regenerateToolpath(entityIds, toolpathBlock);
Where entityIds is an array of all entity IDs to be used for the toolpath and toolpathBlock is the toolpath block created to host this toolpath.
In a nutshell, that's the process a script could use to create tools and toolpaths fully automatically.
Re: Automating QCAD/CAM 3 functions using scripts
Posted: Tue Dec 14, 2021 11:01 pm
by fertig
ahhh amazing, thanks a lot, thats all i needed! now I'm struggling a bit because my dxf export doesnt allow me to define attdefs, but i guess i can get around this by scripting something to split a standard text and make it an attdef in qcad.
thumbsup for the super quick reply by the way! =D
Re: Automating QCAD/CAM 3 functions using scripts
Posted: Wed Dec 15, 2021 8:55 am
by andrew
fertig wrote: āTue Dec 14, 2021 11:01 pm
now I'm struggling a bit because my dxf export doesnt allow me to define attdefs
Note that these custom properties are not attribute definitions (ATTDEF) or block attributes (ATTRIB). They are stored in DXF/DWG as XDATA of those blocks. In DXF, extra lines are appended to the BLOCK_RECORD, for example for attribute "a" with value "123":