Export sketch as SVG: result has an offset from origin

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
Lupin
Posts: 74
Joined: Sat Mar 13, 2021 10:55 am

Export sketch as SVG: result has an offset from origin

Post by Lupin »

Apart from 3D modelling I like FreeCAD's sketcher to draw parametrized 2D shapes. Even for so "lowly" tasks as creating SVG symbols for webpage UIs in browsers (after doing some additional work with inkscape on them), but mostly to later centercut them with a router V-bit (e. g. for front panel labeling; I use FlatCAM for that, as it usually is a project I route PCBs for). I export sketches as "flattened SVG" for that. The small issue with that is, that the generated SVG has an offset compared to the sketch. This is the SVG output of a FreeCAD sketch that is just a 10x10mm² square:

Code: Select all

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="10.2mm" height="10.2mm" viewBox="0 0 10.2 10.2" xmlns="http://www.w3.org/2000/svg" version="1.1">
<g id="Sketch" transform="translate(0.100000,10.100000) scale(1,-1)">
<path id="Sketch_w0000"  d="M 0.0 0.0 L 10.0 0.0 L 10.0 10.0 L 0.0 10.0 L 0.0 0.0 " stroke="#000000" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-opacity:1;fill-rule: evenodd"/>
<title>b'Sketch'</title>
</g>
</svg>
The "path" is totally fine (you can see the corner coordinates of "0.0" and "10.0"). But the "g" element has a transform attribute of "translate(0.100000,10.100000) scale(1,-1)". I guess the scale by -1 and offset of 10 is because FreeCAD's and SVG's y coordinate are flipped with respective to each other. But I don't understand where the extra offset of 0.1mm in the x and y direction is coming from. That offset is not always 0.1mm by the way. It can have other values as well. It isn't hard to fix that by editing the SVG in a simple text editor, but it is another step to forget, and as the offset usually isn't large it isn't obvious enough to catch it on the CNC before routing.

Is there a setting to get rid of this offset?
Lupin
Posts: 74
Joined: Sat Mar 13, 2021 10:55 am

Re: Export sketch as SVG: result has an offset from origin

Post by Lupin »

Scratch that. I saw that there is an option for "raw" export in the settings, which removes that offset.

[EDIT] I just checked with FlatCAM and Inkscape. The lines don't appear in the correct absolute position (including negative coordinates), unless I have to delete the "width", "height" and "viewBox" attributes of the SVG tag completely. But I don't think that's a fault of KiCAD, but more how those programs handle imports.

Inkscape will always put the top left corner of the bounding box of the sketch at the drawing origin. But for me the absolute position usually isn't that important in Inkscape.

FlatCAM seems to put the SVG drawing origin at (0, Y_), where Y_ is the SVG's height attribute. So FlatCAM is weird in that case. But what I found does work fine, is importing a DXF. What would be nice of FreeCAD though, would be to populate the file type selection dialog with only those file types that are valid for the currently selected object. I first thought you couldn't export a sketch at SVG at all, because the export failed with the filetype set to "Drawing (*.svg *.svgz *.dxf)". I only later saw that there are several entries for *.svg and "Flattened SVG" has to be selcted for sketches. The same with DXF. It is confusing that there are the types of "Autodesk DXF", "Drawing" and "Technical Drawing" for *.dxf, but Autodesk DXF has to be used for sketches.
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Export sketch as SVG: result has an offset from origin

Post by GeneFC »

You should only make that mistake once. 8-)

Seriously, maintaining a valid list of possible FreeCAD objects allowable for every type of export sounds like a nightmare to manage. If you get it wrong there is usually an error message, so you are not left wondering what happened.

Gene
Post Reply