Units once more, DXF import trouble

My office uses AutoCad 2018 and FreeCad and LibreCad cannot open the DXF at all. It seems that every AutoCad release breaks the Opensource projects. Unfortunately DXF is not an open standard

1 Like

David, have an example file? If we are to make kicad work with all these sources, saying “Read this string and it will work” is going to be very quick for the devs to bake in,

To maui, Again, its not clear that they follow the same unit table, because feet would not make sense for an inch scaled file.

So digging more, the attached file is exported from Autocad R11/R12,
http://help.autodesk.com/view/ACD/2017/ENU/?guid=GUID-A85E8E67-27CD-4C59-BE61-4DC9FADBE74A

Equally it does appear autocad keeps its dxf format pretty open,

https://github.com/KiCad/kicad-source-mirror/blob/master/pcbnew/import_dxf/dxf2brd_items.cpp#L515

they try to break data interchange all the time…

1 Like

Ok for $LUNITS and $AUNITS, 1 is deg/min/sec format, 2 is decimal format.

And for all autocad files, it defaults to Inches if the $INSUNITS flag is not present.

So the patch for autocad files would be, (Psudo code)

IF($ACADVER exists & $INSUNITS does not)
m_DXF2mm = 25.4;

That should be a pretty simple patch to make autocad DXF units reliable.

I created the following thread on the FreeCAD forum:
https://forum.freecadweb.org/viewtopic.php?f=8&t=28925

@aaltomikael Can you access the thread above and tell us if you have that FreeCAD option enabled or not?

Looks like the exact patch would be:

void DXF2BRD_CONVERTER::addHeader( const DRW_Header* data )
{
    std::map<std::string, DRW_Variant*>::const_iterator it;
    m_DXF2mm = 1.0; // assume no scale factor

    for( it = data->vars.begin(); it != data->vars.end(); ++it )
    {
        std::string key = ( (*it).first ).c_str();

        if( key == "$DWGCODEPAGE" )
        {
            DRW_Variant* var = (*it).second;
            m_codePage = ( *var->content.s );
        }
        else if( key == "$INSUNITS" )
        {
            DRW_Variant* var = (*it).second;

            switch( var->content.i )
            {
            case 1:     // inches
                m_DXF2mm = 25.4;
                break;

            case 2:     // feet
                m_DXF2mm = 304.8;
                break;

            case 5:     // centimeters
                m_DXF2mm = 10.0;
                break;

            case 6:     // meters
                m_DXF2mm = 1000.0;
                break;

            case 8:     // microinches
                m_DXF2mm = 2.54e-5;
                break;

            case 9:     // mils
                m_DXF2mm = 0.0254;
                break;

            case 10:    // yards
                m_DXF2mm = 914.4;
                break;

            case 11:    // Angstroms
                m_DXF2mm = 1.0e-7;
                break;

            case 12:    // nanometers
                m_DXF2mm = 1.0e-6;
                break;

            case 13:    // micrometers
                m_DXF2mm = 1.0e-3;
                break;

            case 14:    // decimeters
                m_DXF2mm = 100.0;
                break;

            default:
                // use the default of 1.0 for:
                // 0: Unspecified Units
                // 4: mm
                // 3: miles
                // 7: kilometers
                // 15: decameters
                // 16: hectometers
                // 17: gigameters
                // 18: AU
                // 19: lightyears
                // 20: parsecs
                break;
            }
        }
        else if( key == "$ACADVER" )
        {
            DRW_Variant* var = (*it).second;
             m_DXF2mm = 25.4;
        }
    }
}

Not yet on launchpad, but may make an account tommorow if nothing new comes up.

No it’s not enabled. Please don’t say this was the solution… I can’t test unitil tomorrow,
but I’ll suppose this solves it. I’ll get back asap after test.
->I noticed the “legacy”-thing, but really thought it was something old and obsolete ?

We’ll see. Latest post on FreeCAD forum indicates the mentioned option may not affect export at all

Humm I think this patch would force inches instead of millimeter, opposite to what is now… so it wouldn’t solve the issue, but just will add a different behavior from before…

The best is to fix FreeCAD exporter, adding units info to DXF file.

The fun you find while digging into obscure specifications

$INSUNITS was introduced in the “Autocad 2000” specification for DXF.

This means any export methods set to AC1006 = R10, AC1009 = R11 and R12, AC1012 = R13 or AC1014 = R14. Will not have that tag present if the tool is respecting the export option,

Freecads export is for AC1009 / R12, so it will never include that tag so long as they are following the specification, and to include it would involve them remaking the exporter to support whatever the Autocad 2000 version is.

Before this, It was simply that DXF files where unitless, Most tools like solidworks and Autocad assumed this to be in inches if not specified on import,

So my psuodocode would then become
When ACDVER = AC1006 or AC1009 or AC1012 or AC1014,
Import as inches,

Now with new info, It would imply the need to add a units dropdown box to kicad to resolve this correctly. as not every tool will export as inches.

5 Likes

+1 :smiley: from my side … (I reached 20 chars :wink: )

Now would be the time to create a bug report. The devs do not really follow this forum.
More info see: I found a bug. What now?

Go right ahead, I dont use DXF myself, someone who uses the functions would be in a better position to see it through.

Good idea. This is a simple box outline, not sure which box vendor it originally came from.
Top file is from web, fails to show in KiCad, no errors.
_R12 version is saved-as from LibreCAD, and it loads fine into KiCad
_R2007 is saved-as from LibreCAD, and it fails to show in kiCad

Mod Case.dxf (41.2 KB)
Mod Case_LC_R12.dxf (203.2 KB)
Mod Case_LC_2007.dxf (28.3 KB)

The first file and the last file are saved as autocad 2007 format. They are more or less the same thing, just the web one liked adding a decimal point to everything for no clear reason, e.g. 0 becomes 0.0 and 1 becomes 1.0, bumping up the file size.

It appears that it heavily records things in “Splines” while the older format records in vertexs (small straight segments)

Edit: On furthur reading, Kicad does not support splines at all, It may be added later, but for now that is what is preventing its import.

and as a fix for using librecad,

1 Like

Well, now it’s working as it should, with the “legacy” tagged.

What changed ?
I’m unclear here, are fixes applied to KiCad, or FreeCAD ?

It looks like he enabled the “legacy” option as shown in the freecad thread here.

That option relates to DXF import, and there is some discussion as to whether it affects export also.

There was also a PR merged in FreeCAD yesterday which may be relevant: Dxf export improvements

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.