Read value from Layer name to zMax value?

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
artisanicview
Active Member
Posts: 33
Joined: Sat Jun 19, 2010 6:23 pm

Read value from Layer name to zMax value?

Post by artisanicview » Fri Jun 14, 2024 10:36 am

How I can make QCAD/CAM to read the name of a layer and interpret the last digits value as "zMax" value for the postprocessor?

I do have a layer in my DXF files that defines the thickness of the material I do need to use when generating the Gcode and on the postprocessor I do have a "zMax" value that I would like to set automatically by reading the last digits from the desired layer name.

So, for my layer name "XLYP1H18" that I do use, the "zMax" value should be 18. I do use another CAM software who it is doing this automatically for me.

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: Read value from Layer name to zMax value?

Post by CVH » Fri Jun 14, 2024 11:10 am

We are basically turning in circles.

The thickness of your material has no meaning in QCAD/CAM.
For QCAD/CAM Ztop material is zero.
We don't account for the thickness with the danger that we cut into our machine bed.

The other approach seen in some classes of machinery is that Ztop of the machine bed is zero.
And then you need the thickness to avoid traversing in X/Y when not above the material.

Both systems have pros and cons.

I know this pops up so now and then and lately more in combination with Maestro.
And then the most important questions are:
Why configuring dxf layers names intended for Maestro but use another CAM?
Why not use the dedicated CAM?

It's basically an offset but I have yet to see the first implementation of the 'other approach'.

When retro-fitting my engraver I also opted for the more conventional approach. :wink:

One could write a script that scans the document layer names and filter on those starting with 'XLYP1H'
Then taking the thickness and store that in a variable.
The question is then what to do with that.

Regards,
CVH

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: Read value from Layer name to zMax value?

Post by CVH » Sat Jun 15, 2024 3:49 am

Script code like this would retrieve the value that is trailing in the XLYP1Hxxx layername, if any.

Code: Select all

var this.zMax = undefined;
var doc = this.getDocument();
var layerIds = doc.queryAllLayers();
for (var i=0; i<layerIds.length; i++) {
    var layerId = layerIds[i];
    var layer = doc.queryLayer(layerId);
    if (layer.isNull()) {
        continue;
    }
    var layerName = layer.getName();
    if (layerName.toUpperCase().startsWith("XLYP1H")) {
        var value = parseFloat(layerName.substring(6));
        if (isNumber(value)) {
            if (isNull(this.zMax)) {
                this.zMax = value;
            }
            else if (value !== this.zMax) {
                this.zMax = "ambiguous";
                break;
            }
        }
    }
}
if (isNull(this.zMax)) {
    this.zMax = "Undefined";
}
Only the first meaningful value after "XLYP1H" is parsed, leading and trailing spaces are ignored.
If the first character cannot be converted, NaN is returned and that condition is skipped here.
Board material is never 18mm exact ... :wink:
Opted for parseFloat(...) but you could parse integers or only the integer part with parseInt(...).
Floats are with a decimal dot, not with a comma.

If it finds more than one layer starting with "XLYP1H" and with a different value the result is "ambiguous".
-> Also meaning that this layer may have sub-layers, internally they all start with the parent layer name.
Without such a layer or when it can't be converted to a number the result is "Undefined".
In other cases it is a valid number.

It then depends if this.zMax is in scope where you want to use it.

Regards,
CVH

Post Reply

Return to “QCAD/CAM”