DXF export scaling

Bug #1643383 reported by Laurence Gonsalves
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Inkscape
Fix Released
Medium
Unassigned

Bug Description

Saving as "Desktop Cutting Plotter (AutoCAD DXF R14) (*.dxf)" seems to scale up the drawing by about 6%.

To reproduce:

1. Create a new drawing.

2. In Document Properties set the page size to something other than A4, and set the units to mm. (I don't know if either of these are necessary to reproduce)

3. Draw a 100x100mm rectangle.

4. Save a copy. Choose "Desktop Cutting Plotter (AutoCAD DXF R14) (*.dxf)" as the format. Disable "use ROBO-Master" and "use LWPOLYLINE" (though I don't think either setting matters). Set Base unit to mm.

5. Import the exported DXF into the same drawing. Disable "Use automatic scaling to size A4", and set manual scale factor to 1.0. Note that the imported rectangle is now 106.371mm on each side.

To narrow down whether this was an import or export problem, I tried loading the DXF into OpenSCAD. OpenSCAD also shows the rectangle as being 106.371mm on each side, so it seems that the exported DXF has the wrong size, which suggests that import is fine, but export is scaling things.

Revision history for this message
Laurence Gonsalves (laurence-xenomachina) wrote :
Revision history for this message
Laurence Gonsalves (laurence-xenomachina) wrote :
jazzynico (jazzynico)
tags: added: dxf exporting importing units
Revision history for this message
jazzynico (jazzynico) wrote :

Reproduced on Xubuntu 16.04, Inkscape 0.91.

Also reproduced with lp:inkscape/0.92.x rev. 15207, but with a different result. The exported rectangle is now 99.729mm on each size. It's a bit better, but it's still not exactly the correct value.

Changed in inkscape:
importance: Undecided → Medium
milestone: none → 0.92
status: New → Triaged
tags: removed: importing
Revision history for this message
jazzynico (jazzynico) wrote :

Possibly related:
 - bug #1525418 "DXF export fixed to 96 dpi, should use user unit scale"
 - bug #1576373 "scale of exported dxf not the same after import and open of pdf via poppler"
 - bug #1640624 "SVG files from LibreOffice opened in Inkscape export to dxf at incorrect scale."

Revision history for this message
TylerDurden (8thrule) wrote :

Testing 0.92 win 8.1...

With document scale set to 1:1px (96dpi), export of 100x100mm DFX opens properly in Inkscape, Sheetcam, MoI3D and Geomagic Design.

Similar results with 10x10in DXF from Inkscape to target programs.

Revision history for this message
James Wallbank (james555) wrote :

I've just upgraded to Inkscape 0.92.0 r15299 and have also noticed a change in behaviour with scaling for DXF export. It used to be that to get the correct scale in my laser software I needed to save off with the DXF option "Units: mm". Now 0.92 generates a file with the wrong size with "Units: mm" but the right size with the export option "Units: px". That's counter-intuitive! Something about DXF export scaling has gone screwy! It's definitely to do with export, not import.

Revision history for this message
Alvin Penner (apenner) wrote :

just writing to confirm the output scaling behavior. If the document units of the original svg file are in mm, which is now the default behavior, then you will need to choose the Base Unit to be px in the dxf output dialog in order to get the correct output size. And if the original svg document units were px then you will need to choose mm as the base unit on output.

I believe this change was made in Dec 27, 2010, see:
http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/revision/9984

Unfortunately, I can no longer remember why this change was made, I'll look into it tomorrow to refresh my memory. It has to do with the question of whether the base unit represents units of the source or the destination, but I cannot remember exactly why this particular choice was made. Will report back when I know more. Other than that the conversion is very precise, as far as I can tell.

Revision history for this message
Alvin Penner (apenner) wrote :

I have not been able to locate a precise reference as to why commit 9984 was made. However here is some documentation associated with that commit:

- assume svg drawing is in pixels, at 90 dpi.
- only line and spline elements are supported.
- ROBO-Master spline output is a specialized spline readable only by ROBO-Master and AutoDesk viewers, not Inkscape.
- LWPOLYLINE output is a multiply-connected polyline, disable it to use a legacy version of the LINE output.

The 90 dpi has since been replaced with 96 dpi. The main point is that the intent of the Base Unit parameter is to specify the units of the output device, not the svg file. This is why the behavior is backwards or unintuitive.

On a side note, changing the svg document units should not affect the output size in any way, and a separate bug report has been raised for that, Bug 1660967, since that is not related to this bug report.

Revision history for this message
KarelWullaert (karel-9) wrote :

I had a similar problem.
I solved it by setting the document property: scale to 1
Apparently this scale is on 0.975.. or something when you install Inkscape.
Then I import my image again and traced that also again, used for both the document units and the export for DXF 'mm'.
Now the dimensions are correct.
Hope this helps. Please feel free to write me if any questions.
Karel

Revision history for this message
Laurence Gonsalves (laurence-xenomachina) wrote :

karel-9, how does one set "the document property: scale to 1"? I looked under File -> Document Properties, but don't see any "scale" setting in any of the tabs.

Revision history for this message
Aaron (eidylon) wrote :

I am experiencing a similar issue.

I did up a drawing in mm; the document properties unit is mm, the grid size is mm, the document properties scale is 1:1.

I save the file as a DXF. I am then trying to import it into LaserCut to feed into a laser cutter.
(https://wiki.nottinghack.org.uk/wiki/Laser_cutter/LaserCut)

When I import the DXF into LaserCut, it comes out at approximately 1/4 the actual size.
In order to get it to be the right size in the plotting software, I need to resize my drawing to approximately 375% in Inkscape.

The attached zip contains an SVG with a 5cm square, and the corresponding DXF.

Revision history for this message
Aaron (eidylon) wrote :

Oh... forgot to add, I am using Inkscape v. 0.92.1 r15371 from the Windows 10 app store.

Revision history for this message
Alvin Penner (apenner) wrote :

Aaron - thank you for submitting this report.

I am not able to reproduce the problem on Windows 10, Inkscape 0.92.2
attached is the result I get if I export the drawing to dxf using Base Unit = mm.
could you check to see if you used the same Base Unit?

note that this behavior was recently modified in response to Bug 1660967
https://bugs.launchpad.net/inkscape/+bug/1660967

Revision history for this message
Aaron (eidylon) wrote :

Yes, my base unit when saving as DXF is set to mm.
I downloaded your dxf, and tried to open it in LaserCut, and it cannot read the DXF.
It gives an error about "Seek failed on <filename>."

Revision history for this message
Alvin Penner (apenner) wrote :

it is possible that may be due to the fact that I was using the LWPOLYLINE element. Here is a version that has the same size but uses only the LINE element.

Revision history for this message
Alvin Penner (apenner) wrote :

I just realized, it is also possible that you may need to upgrade to rev 92.2, which was just released.

see:
https://inkscape.org/en/release/0.92.2/

Revision history for this message
swulf (swulf) wrote :

I am having similar difficulties. I am creating a DXF in Inkscape 0.92.1 r15371 and am exporting to LibreCAD Version: 2.1.3 under Windows 7 64. Here is my experience so far.

Inkscape configuration:

 Document Properties:

  Display Units: mm
  Page Size: US Letter
  Orientation: Portrait
  Custom Size: 8.5 x 11 inches
  Scale: X: 1.00000 Y: 1.00000 User units per mm
  Display: Use antialiasing

I have created a 50 mm by 75 mm rectangle and saved it as 'Desktop Cutting Plotter (AutoCAD DXF R14). No fill, stroke width set to 0.059 mm.

Save options:

 NOT SELECTED - use ROBO -Master type of spline output
 NOT SELECTED - use LWPOLYLINE type of line output
 Base unit: px
 Character encoding: Latin1
 Layer export selection: All (default)
 Layer match name: <blank>

In LibreCAD, opening the file and measuring it with the built-in tools reports that the rectangle is 49.9411 x 74.9706 mm. Close, but no banana.

Any idea what is going on? Seems like this should be straight-forward.

Revision history for this message
Alvin Penner (apenner) wrote :

@swulf - it looks like there may be a confusion here as to whether one is using a geometric bounding box (which does not include stroke width) or a visual bounding box (which includes stroke width). The dxf output will correspond to the geometric bounding box, which will be slightly smaller.
    If you draw a rectangle and inspect its dimensions immediately at the top you will see the 'geometric' size. When you switch to the Select Tool, F1, you will see its 'visual' size displayed.
    Alternatively, if you want to confirm the geometric size, open the menu item Edit->XML Editor. The width and height properties shown here will give you the geometric size which is what the dxf will use as well.

Revision history for this message
unfa (unfa00) wrote :

I had a similar problem. My document scale was 3.54331
After setting it to 1 the problem is gone - exported DXF shows the same dimensions in LibreCAD as the SVG.

Revision history for this message
Hachmann (marenhachmann) wrote :

I suspect this is relevant: https://inkscape.org/en/learn/faq/#inkscape-092-my-drawings-are-just-quarter-their-original-size-when-i-open-them-program-xyz , because it explains some of the underlying issues and provides links. It's not a 100% match, though.

Revision history for this message
Alvin Penner (apenner) wrote :

the problem in comment 20 is probably related to this bug:
https://bugs.launchpad.net/inkscape/+bug/1672066

a fix for this was committed to trunk in:
http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/revision/15590

but I do not think this was ever committed to the 0.92.x branch

Revision history for this message
Alvin Penner (apenner) wrote :

a merge request to backport the latest changes in dxf_outlines.py to the 0.92.x branch has been issued at:

https://gitlab.com/inkscape/inkscape/merge_requests/186

Revision history for this message
Hachmann (marenhachmann) wrote :

Can this be marked as fix committed, too?

Revision history for this message
Alvin Penner (apenner) wrote :

yes, I think so.
Unfortunately this report contains quite a variety of different and possibly unrelated problems, but I think the majority of them have been fixed. And I was never able to reproduce the original problem in the first place, so I think it would be best to mark it as Fix Committed.

Revision history for this message
Laurence Gonsalves (laurence-xenomachina) wrote :

FWIW, I can still reproduce this problem using 0.92.2 (from the Inkscape Stable PPA) on Ubuntu 16.04.3 LTS. The only difference from when I originally reported this is that the incorrect size has actually gotten slightly worse: my 100mm square now re-imports as 106.667mm on each side.

Is there a different version I should be testing with or some other information you need to reproduce?

Revision history for this message
Alvin Penner (apenner) wrote :

thanks for the feedback. I just did the experiment on Windows 10, Inkscape 0.92.2 (5c3e80d, 2017-08-06)
Here is the original svg file with a rectangle

Revision history for this message
Alvin Penner (apenner) wrote :

here is the dxf file I get, which appears to be the correct size.

If you are not using 0.92.2 from August 2017 or later, it would probably be a good idea to upgrade, unfortunately I don't know how that is done on Linux...

alternatively can you attach your source svg file and the resulting dxf?

Revision history for this message
Alvin Penner (apenner) wrote :

sorry, I just re-did the test using the svg file from comment 1. It appears that part of the problem is due to the difference between visual bbox and geometric bbox. The rectangle in the svg file from comment 1 has a dimension of 99.458 mm not 100. The visual bbox is 100 but the geometric bbox is 99.458 and this is what controls the size of the dxf file. If I export this to dxf I get a dxf size of 99.458 as well, so the result is as expected.

Revision history for this message
Laurence Gonsalves (laurence-xenomachina) wrote :

I loaded up your SVG and saved a DXF copy per the original comment. I've attached the resulting DXF, which is different from the one you posted. When I reimport it the square is the wrong size, but if I import your DXF the square is the correct size, indicating that the bug is at export time. (consistent with the original report)

The release I'm using is the latest from this PPA: https://launchpad.net/~inkscape.dev/+archive/ubuntu/stable

The version is 0.92.2+68~ubuntu16.04.1

Revision history for this message
Alvin Penner (apenner) wrote :

the problem you are having is consistent with the change in default dpi from 90 to 96. However this change in the dxf export routine was made quite a while ago, so I am surprised that it is showing up now.

there are two things to check:
1. do a scan of your entire machine to make sure that there is one and only one version of dxf_outlines.py on your machine. Delete or rename or upgrade any old versions.

2. download the latest version of this file from:
https://gitlab.com/inkscape/inkscape/tree/master/share/extensions
make a backup of your existing version of this file and try the new one. It will be in the directory Inkscape\share\extensions\ or something similar to that.

Revision history for this message
Laurence Gonsalves (laurence-xenomachina) wrote :

Ok, I searched and the only dxf_outlines.py on my machine is /usr/share/inkscape/extensions/dxf_outlines.py

That file comes from the PPA package. I just checked, and it is the same as the dxf_outlines.py in the latest release source tarball on inkscape.org (except the shebang line). It is, however, several versions older than the latest version in the repo you linked to.

I tried replacing it as you suggested. I restarted Inkscape and tried the test with the 100mm100mm.svg you uploaded earlier. Even with the latest dxf_outlines.py I still get 106.667mm when I export and re-import the DXF. (I'm turning off the stroke when measuring this, which I believe should avoid the visual bbox vs geometric bbox issue -- please correct me if I'm wrong.) I've attached the resulting DXF. It's very slightly different from what I was getting before, but by less than a thousandth of a mm.

To verify that that really is the dxf_outlines.py being executed, I inserted a `raise` statement near the top, and confirmed that the exception is thrown when I attempt to save a DXF. Inkscape displays a dialog with the stacktrace.

You mentioned DPI earlier on -- just to sanity check, is DXF export influenced by my machine's DPI setting?

Revision history for this message
Alvin Penner (apenner) wrote :

I just realized something. There is a possibility that these conversion factors are actually coming from the inx file which was also changed at some point. Here is the inx file that I am using, latest version. It contains conversion factors such as
    <_item value="25.4/96">mm</_item>
    <_item value="2.54/96">cm</_item>
    <_item value=".0254/96">m</_item>
    <_item value="1./96">in</_item>
which are based on 96 dpi instead of the old 90 dpi. Give this a try and see if it helps. The most recent version is also available at:
https://gitlab.com/inkscape/inkscape/tree/master/share/extensions

Revision history for this message
Laurence Gonsalves (laurence-xenomachina) wrote :

I tried that out, and there was no change. Afterwards I realized that that inx file seems to be identical to the one already on my system. :-(

Revision history for this message
Alvin Penner (apenner) wrote :

well in that case, I am at a loss, since I cannot reproduce the problem.

can you just check one more thing? When you load my file 100mm100mm.svg, the one from comment 27, can you load the Document Properties Dialog, File->Document Properties, and confirm that the Scale x = 1, and the Display Units = mm?
also, just to double-check, I am curious about the actual release date on Inkscape, can you load the Help->About item and report the release details. In my case I get Inkscape 0.92.2 (5c3e80d, 2017-08-06)

Revision history for this message
Alvin Penner (apenner) wrote :

also, one last thing: can you check to make sure there is only one version of dxf_outlines.inx on your machine, since this is the most likely source of the problem.

Revision history for this message
Alvin Penner (apenner) wrote :

something else to check:
go to the preferences file at:
C:\Users\username\AppData\Roaming\inkscape\preferences.xml
unfortunately your address will be different than this, but should be similar.

in this file, search for the tag:
org.ekips.output.dxf_outlines.units="25.4/96"

if the conversion factor that you see here is not the same as yours, that is likely the problem. In this case, try to force a refresh by:
- close the preferences file
- start Inkscape and perform a dxf output with a different Base Unit
- close Inkscape and restart it and set the Base Unit back to mm.

Alvin Penner (apenner)
Changed in inkscape:
status: Triaged → Incomplete
Revision history for this message
Ducon Lajoie (dlajoie) wrote :

Hello,

I faced this same issue, which seems deeply related to the DPI mess that's been bothering us for so long.

Inkscape version: 0.92.2 (Gentoo)

While trying out different things, I got different scaling values : sometimes correct, sometimes not..

Since I mostly work with metric units, I like one pixel too be equal to 1 mm as it really eases drawing scaled objects. I struggled too get it right a few times over, often having to do it again because I couldn't remember where/how this was to be done. Fortunately, I saved a "metric.svg" file with the correct settings.

Since I installed Big Blue Saw DXF export (which, by the way, did not work _at_all_ for me) I was instructed to modify /usr/share/inkscape/extensions/inch_dxf_outlines.py - and that set me on the right track.

Looking at /usr/share/inkscape/templates/default.svg and comparing it with my metric.svg file, I spotted the differences and finally updated the default.svg (as well as default.fr.svg to match my locale).

The modifications are as follows:

     inkscape:cx="325.24126"
     inkscape:cy="366.46706"

(as far as I can remember, the values were found somewhere on the internet)

The complete working default.svg is attached. Don't forget to copy/symlink for your locale.

Now, everything in inkscape is in [mm] ; 1 [px] == 1 [mm] and DXF export is scaled correctly.

I would mark this bug as "fixed for now" :-)

Changed in inkscape:
status: Incomplete → Fix Committed
Revision history for this message
Ducon Lajoie (dlajoie) wrote :

> Now, everything in inkscape is in [mm] ; 1 [px] == 1 [mm] and DXF export is scaled correctly.

A "pixel" is technically a "media unit" (screen or printer), so to make it clear: one SVG unit == one millimetre, so

 <rect
  [snip]
  width="100"
  height="100"
  x="50"
  y="70" />

will create a 100x100 [mm] square placed at {50,70} [mm] from the page reference.

Revision history for this message
Ducon Lajoie (dlajoie) wrote :

IMHO, things will be definitely fixed when all references to the arbitrary values of 90/96 DPI have been removed from the codebase

Max Gaukler (mgmax)
Changed in inkscape:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.