Automating QCAD/CAM 3 functions using scripts
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Indicate the post processor used.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Indicate the post processor used.
Attach drawing files and screenshots.
Post one question per topic.
Automating QCAD/CAM 3 functions using scripts
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!
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
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.
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
Hi Andrew,
Thanks for your reply and help with explaining the toolpath blocks, I 'll give it a go..
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
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) .
Is it possible to perform the same customization with "CAM Export" and postprocessor scripts?
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>]";
};
Re: Automating QCAD/CAM 3 functions using scripts
I'll see how this can be made available again.raemin wrote: ↑Mon Sep 06, 2021 8:11 pmThe link to CamExporterV2 (https://www.qcad.org/doc/qcad/latest/de ... er_v2.html) seems broken, any updated doc/link?
Formatting can be done while registering a variable. For example:Is it possible to perform the same customization with "CAM Export" and postprocessor scripts?
Code: Select all
this.registerVariable("xPosition", "X", true, "X", 4, { factor: 10, sign: true });
- "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
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
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
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: Block representing a toolpath: To generate the toolpath geometry, you could then call
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.
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: Block representing a toolpath: To generate the toolpath geometry, you could then call
Code: Select all
Cam.regenerateToolpath(entityIds, toolpathBlock);
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
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
thumbsup for the super quick reply by the way! =D
Re: Automating QCAD/CAM 3 functions using scripts
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":
Code: Select all
1001
QCAD
1000
a:123