Function Order

Discussions around the CAM Add-On of QCAD.

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.

Post Reply
jthornton
Full Member
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm

Function Order

Post by jthornton » Sun Nov 17, 2013 4:17 pm

Are the functions called in some kind of order in GCode.js or is it top down execution?

When you create a new configuration file do you need to keep the new functions in the same order as GCode.js?

Thanks
JT

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

Re: Function Order

Post by andrew » Sun Nov 17, 2013 10:09 pm

The order in the file is irrelevant (as with any functional programming I am aware of).

The call stack looks roughly like this:
writeHeader
exportFile
    exportDocument
        exportEntities
            exportContour (for each contour)
                exportContourEntity (for each entity in that contour)
                    exportEntity
                        exportLineSegment (for each line segment of the broken down entity)
                            writeRapidLinearMove (if the segment does not connect to the previous segment)
                            writeLinearMove
                        exportArcSegment (for each arc segment of the broken down entity)
                            writeRapidLinearMove (if the segment does not connect to the previous segment)
                            writeCircularMove
writeFooter
There are a lot more functions obviously, but these are the most important ones that are called by QCAD/CAM directly or indirectly by default.
Any of these functions can be overwritten by a machine configuration which can of course change the whole call stack completely.

jthornton
Full Member
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm

Re: Function Order

Post by jthornton » Mon Nov 18, 2013 1:42 pm

Andrew,

That helps me understand where I was having some difficulty, thanks for posting that.

JT

jthornton
Full Member
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm

Re: Function Order

Post by jthornton » Mon Nov 18, 2013 11:31 pm

Does writeHeader come before the creation of the CAM Configuration page? Does exportFile or exportDocument create the CAM Configuration page? If so that explains why I could not get my layer options in writeHeader where I was hoping to put a comment stating the torch settings.

JT

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

Re: Function Order

Post by andrew » Mon Nov 18, 2013 11:39 pm

jthornton wrote:Does writeHeader come before the creation of the CAM Configuration page? Does exportFile or exportDocument create the CAM Configuration page?
No and no. The dialog is configured and displayed before anything is being exported.

jthornton
Full Member
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm

Re: Function Order

Post by jthornton » Tue Nov 19, 2013 1:28 pm

I can't seem to get anything to work in writeHeader that calls another function. The following code fails for some reason that I don't understand.

Code: Select all

// add preamble
Plasma.prototype.writeHeader = function() {
    this.writeLine("G20 G17 G40 G49 G54 G64 P0.005 G80 G90 G94");
    this.torchNozzle = this.getTorchNozzle();
    qDebug(this.torchNozzle);
    this.writeRapidZMove(this.getSafetyZLevel());
    this.toolPosition = GCode.ToolPosition.Clear;
};
// get the nozzle type
Plasma.prototype.getTorchNozzle = function() {
    //You can get the current layer as follows:
    var entity = this.getEntity();
    var layerId = entity.getLayerId();
    var layer = this.document.queryLayer(layerId);
    return layer.getCustomProperty("QCADCAM", "Cam/TorchNozzle", "manual");
};
However if I move the call to writeToolDown it will work.

Code: Select all

// probe for material top and fire the torch
Plasma.prototype.writeToolDown = function() {
    this.g = GCode.Mode.Normal;
    this.z = this.getToolDownLevel();
    this.torchNozzle = this.getTorchNozzle();
    qDebug(this.torchNozzle);
    this.toolPosition = GCode.ToolPosition.Down;
    this.writeLine();
    this.toolIsDown();
};
Thanks
JT

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

Re: Function Order

Post by andrew » Tue Nov 19, 2013 2:27 pm

When writeHeader is called, there is no current entity yet (entities are exported later), so this.getEntity(); probably returns null.

You might also want to use the script debugger to investigate such problems. Simply start QCAD with the command line switch -enable-script-debugger:
qcad -enable-script-debugger

jthornton
Full Member
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm

Re: Function Order

Post by jthornton » Tue Nov 19, 2013 11:37 pm

Andrew, thanks again... I forgot about the script debugger with so much new info floating between my ears.

JT

Post Reply

Return to “QCAD/CAM”