Units of measure in dxf import

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!
demackison
Posts: 67
Joined: Mon Nov 24, 2014 7:54 pm

Units of measure in dxf import

Post by demackison »

Is there a way to specify units of measure when importing a dxf file? I am attempting to import a flat file and it appears the person who created the file was using inches instead of millimeters, so his 4.25 inch wide scale drawing imports as 4.25 mm wide.


OS: Windows 8.1
Word size of OS: 64-bit
Word size of FreeCAD: 32-bit
Version: 0.15.4671 (Git)
Branch: releases/FreeCAD-0-15
Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
User avatar
yorik
Founder
Posts: 12866
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Units of measure in dxf import

Post by yorik »

Basically, I know it sounds incredible but it is, the DXF file itself doesn't contain a definition of the unit being used. There is a variable that says in which unit imported blocks are expected, which many application use to choose the unit. But this seems wrong to me, I used autocad for many years and never saw anybody set that variable correctly. There isa lso a setting that says if you want your dimensions in imperial or metric units. And that's all.

So there is no reliable way for FreeCAD to know the unit of the DXF file. I would suggest to simly open it in a DXF app such as librecad and rescale everything to yuor unit of choice... It will be faster than doing it in FreeCAD I think.

We would need a quick tool to rescale a whole document one day...
User avatar
blockitectvt
Posts: 2
Joined: Sun May 09, 2021 6:48 pm
Location: Burlington VT USA
Contact:

Re: Units of measure in dxf import

Post by blockitectvt »

I didn't see this anywhere else, so I thought I would tack this on here - some notes on my recent experience trying to import DXF in inch units:

I made some 2D plans and elevations on Autocad 2016. When trying to import the files to Freecad, I could not get the ODA converter to work properly (some error about moving the dwg file to a path without spaces..), so I exported DXF files from Autocad. Before saving as DXF, I issued the -DWGUNITS command to be sure of the export units Autocad was generating. When I set the units to inches, I then used the 25.4 scale factor in the DXF import settings in Freecad. But when I imported the file, a door that should be 3 feet wide was 1,935'-6 1/2" wide. When I set the scale factor to 1, the same dxf file imported with that same door at 76'-2".

So then I tried to change the scale factor in Freecad to be the equivalent of 1/25.4 = 0.03937, but the best I could enter in the DXF import preferences was 0.0394 - only four decimal places. It was close to the correct scale, but this is not enough precision for reasonable architectural work - a few inches of error over 100 feet.

Back in Autocad I used the -DWGUNITS command again and converted the units from inches to Millimeters. Then I imported the dxf file into Freecad with the scale factor set to 1 and the import was perfect - a 3 foot door measured exactly 3 feet. A 76' length of wall measured 76 feet exactly.

So it seems to me that the scale factor guidance in the "mouseover" in the preferences may need to be reversed. And there needs to be a way to enter more decimal places for the scale factor. Perhaps there is a way to do this from the command line directly? It would be best to have it set up right in the GUI, but if anyone knows how to set this with more precision some other way, that would be helpful to know.

It's good to have some method to get things properly scaled, but it would be nice to be able to simply import from my large library of imperial unit drawings and have Freecad do the unit conversion without having to open 2d CAD and run a conversion. In a production environment, that's a huge chunk of time saved.

-israel smith
Smith Buckley Architects
www.sbavt.com


OS: Windows 10 Version 1909
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24276 (Git)
Build type: Release
Branch: releases/FreeCAD-0-19
Hash: a88db11e0a908f6e38f92bfc5187b13ebe470438
Python version: 3.8.6+
Qt version: 5.15.1
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/United States (en_US)
Israel Smith
Smith Buckley Architects
www.sbavt.com
User avatar
blockitectvt
Posts: 2
Joined: Sun May 09, 2021 6:48 pm
Location: Burlington VT USA
Contact:

Re: Units of measure in dxf import

Post by blockitectvt »

I found the answer to this in another post.

To set the scale factor to go from inches -->> MM the value is 1/25.4 = 0.03937
The difficulty is that the GUI preferences dialog doesn't have that many decimal places. So you have to open: Tools --> Edit Parameters, and then go to "base-app, preferences, Mod Draft, and set the "dxfScaling" parameter to 0.03937, then "save to disk"

After that the preferences dialog will show it rounded to 0.0394, but the precision will be there under the hood.
Israel Smith
Smith Buckley Architects
www.sbavt.com
UR_
Veteran
Posts: 1348
Joined: Tue Jan 03, 2017 8:42 pm

Re: Units of measure in dxf import

Post by UR_ »

Harmonized no. of digits of dxfScaling between Edit->Preferences and Tools->Edit Parameters.




Tools->Edit Parameters:
Screenshot 001.png
Screenshot 001.png (28.84 KiB) Viewed 1320 times


Edit->Preferences:
Screenshot 002.png
Screenshot 002.png (9 KiB) Viewed 1320 times


PR: https://github.com/FreeCAD/FreeCAD/pull/4784
Nabilakroud
Posts: 6
Joined: Mon Jun 27, 2022 11:51 pm

Re: Units of measure in dxf import

Post by Nabilakroud »

Hi there,

First of all, I would thank you very much for your priceless work. 👍🏽
I have similar issue when importing dxf files with mm unit,

- So to detect the origin of this issue
I created a bunch of similar files using LibreCAD, all of them with just a unit rectangle [1×1] (as shown), but each one with a different unit.

and then I imported them to FreeCAD,
freecad.png
freecad.png (29.02 KiB) Viewed 321 times
I have noticed that (when importing mm.dxf file) what was : 1 mm in LibreCAD becomes now 1 inch = 25.4mm in FreeCAD :o

All the other files with the rest of units look like they are well projected.

I opened in.dxf and mm.dxf files in VSC to compare them, as shown below, honestly I'm not expert but I think that in LibreCAD exports the files correctly .
VSC.png
VSC.png (14.53 KiB) Viewed 321 times
User avatar
Roy_043
Veteran
Posts: 5237
Joined: Thu Dec 27, 2018 12:28 pm

Re: Units of measure in dxf import

Post by Roy_043 »

If the image shows all the differences then there is something wrong with the original files. You would also expect different values for the INSUNITS variable. Please post the DXF files you have used.
User avatar
thomas-neemann
Veteran
Posts: 6623
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE

Re: Units of measure in dxf import

Post by thomas-neemann »

Nabilakroud wrote: Sat Jul 02, 2022 12:35 am ...
everything seems to work here
300.dxf
(17.18 KiB) Downloaded 3 times
from librecad



Bildschirmfoto_2022-07-02_11-06-22.png
Bildschirmfoto_2022-07-02_11-06-22.png (9.68 KiB) Viewed 262 times

Bildschirmfoto_2022-07-02_11-06-37.png
Bildschirmfoto_2022-07-02_11-06-37.png (18.36 KiB) Viewed 262 times

Code: Select all

OS: Ubuntu 20.04.1 LTS (XFCE/xubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.20)
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.9.13, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: German/Germany (de_DE)
Installed mods: 
  * InventorLoader 1.3.0
  * Curves 0.5.0
ich biete freecad online-support an, als mini-job
VHS Freecad Webseminare Herbst 2022
https://www.vhs-lingen.de/programm/beru ... 011#inhalt
https://www.vhs-lingen.de/programm/beru ... 012#inhalt
Nabilakroud
Posts: 6
Joined: Mon Jun 27, 2022 11:51 pm

Re: Units of measure in dxf import

Post by Nabilakroud »

Roy_043 wrote: Sat Jul 02, 2022 7:53 am ... Please post the DXF files you have used.
  • mm:
    mm.dxf
    (19.2 KiB) Downloaded 6 times
mm.png
mm.png (21.5 KiB) Viewed 190 times
  • Inches:
    inch.dxf
    (19.23 KiB) Downloaded 2 times
inch.png
inch.png (21.15 KiB) Viewed 190 times
Nabilakroud
Posts: 6
Joined: Mon Jun 27, 2022 11:51 pm

Re: Units of measure in dxf import

Post by Nabilakroud »

thomas-neemann wrote: Sat Jul 02, 2022 9:10 am everything seems to work here
I tried with your file
300.dxf
and it worked well for me too :roll:
Post Reply