Import DXF with arcs from OpenSCAD, FreeCAD or LibreCAD into KiCAD

Is it just me or KiCad->Import->DXF will approximate arcs in Edge.Cuts as straight lines? See the FreeCAD cutout and its corresponding DXF export in KiCad’s Pcbnew (bottom arcs on the left and right sides are lines in KiCad import):

1 Like

It has been a little while since I have imported a custom edge cuts from Freecad. The first thing I would check is the DXF export settings and verify the DXF file looks correct in a third party DXF reader. I seem to recall a case were the export wasn’t what it should be, and the DXF version needed to be changed. Posting your DXF file may let others have a closer look.

Thanks for the feedback and sure, here’s my .dxf file:

nexus4_bottom_flex.dxf (1.9 KB)

It shows fine on Autodesk’s online DXF viewer though (round corners at the bottom):

1 Like

you need to explode your dxf object and then save it
nexus4-exploded.dxf (21.6 KB)
then import it in kicad


I’ve done it in kicad dev, but I suppose it would work also in kicad stable (in case not, after exploding the object save the dxf as R12)

and at the manual

2 Likes

Check the DXF export settings…

Screenshot for non-cloud Autodesk Inventor for that kind of thing:

1 Like

this is an option valid in case of Splines, and thanks for pointing this out… I had troubles once just because of this and it useful for users to know that…
But in case of @brainstorm file, there are only arcs, so no splines were involved (the dxf were fine in dxf viewers)

3 Likes

Ah, you’re right. Was in hurry this morning when I posted that :wink:

Indeed, I went a bit nuts tweaking parameters to make it work @Joan_Sparky @maui, but no reasonable combination of the checkboxes below helps my case, no round arcs show up in KiCad, so I guess we can now call FreeCad limitation? :confused:

Side note: one must be in “Drafts” workspace to access those .DXF preferences in FreeCad, those export settings are apparently not global :-S

EDIT: Exploding the objects as @maui mentioned does the trick though (see first object from the right, rounded corners, finally):

1 Like

no, it is a kicad import dxf limit, that can be found at the manual
http://docs.kicad.org/4.0.5/en/pcbnew.html#_creating_a_board

6.1.2. Using a DXF drawing for the board outline
As a first step, any POLYLINES need to be split (Exploded) into their original simpler shapes. In LibreCAD use the following steps:

  • Open a copy of the DXF file.
  • Select the board shape (selected shapes are shown with dashed lines).
  • In the Modify menu, select Explode.
  • Press ENTER.

From your FC setting menu you have Max Spline segment to 5mm…
Move this setting to 0.01mm as suggested by @Joan_Sparky to be able to export correctly also complex spline (which is not your case atm).

3 Likes

Polylines should work fine. There are bugs that were fixed shortly after the very first 4.0 release. Genuine arcs are used, not approximations. This could cause problems when importing to copper layers since arcs are not allowed on copper layers. Another problem you may encounter is that KiCad will use either 16 or 32 segments per 360 degrees to approximate an arc in the manufacturing output files; a consequence of that is that large arcs will be wrong in the Gerber files even if they look OK in the mechanical exports. Yet another problem which I encountered was that circular copper pour regions are somehow recognized as being circular and the numerous short line segments representing the region are replaced with 16 or 32 points and of course violating the intended design.

I would have to have a closer look at the DXF file to see what is going wrong. Maybe the entity is an ‘arc’ and perhaps that’s still not supported in the importer. In the dialog shown by Joan_Sparky, try by clicking on the “Merge Profiles into Polylines” and see if that makes a difference. The DXF importer is extremely basic and gets very little attention.

[edit]
OK, I had a look at the file and it used PolyLines. I need to find some time to find out why this is failing.

2 Likes

Yes, no worries, setting the spline segment to 0,01mm did the trick as shown in the screenshot above, thanks all :wink:

Is there a KiCad script, option or similar that automatically explodes an OpenSCAD 2D DXF when importing? I keep forgetting to do so and I get blocky Edge.Cuts

Until I remember to manually open FreeCAD or similar and do the exploding/downgrade dance :-S

What would you people use to automate this? I’m thinking on borrowing some code from here: https://github.com/brad/Inkscape-OpenSCAD-DXF-Export

Actually, the steps pointed out by @maui with LibreCAD (Select All, Tools->Modify->Explode) do not seem to work anymore :_(

I’m attaching my current .dxf file as exported by OpenSCAD to see if someone can spot the issue…donut_pcb.dxf (15.2 KB)

The blocky KiCad (rolled back to 4.0.6) imports on the right are imported with different .dxf formats/settings (R12, DXF 2000, 2007, etc…) to no avail. While on the left, the .dxf imported right into LibreCAD from OpenSCAD looks fine, rounded… what am I doing wrong?

Also tried again with FreeCAD with the settings we discussed a while ago (including Max Spline Segment set to 0.01mm), but it does not work either… looks round and fine on FreeCAD, I can “downgrade” or “upgrade” the figure with the right settings as pointed in previous posts, but the layout stays blocky when importing into KiCAD :confused:

That file loads fine for me in 4.0.6 and today’s nightly. OpenSCAD decomposes to lines anyway, and the DXF contains lines (no arcs or polylines), at least it does with the version I use (2015.03-1) There are some options in OpenSCAD to set the effective resolution, e.g. $fs.

This may be a bug to do with localisation, i.e. “,” instead of “.” in numbers, as it appears the values are being truncated to integers.

I edited the file to remove fractional parts and it looks like your picture

Therefore I would say this is probably a bug in KiCad DXF parser. I don’t know if DXF has an option, or if it always uses decimal point for numbers. I would raise an issue on the bug tracker, also attach your DXF file, and mention you are using non-English KiCad.

Try loading this file donut_pcb_comma.dxf (15.2 KB) - decimal point converted to comma, it might go horribly wrong, so make sure changes are saved :slight_smile:

1 Like

Great catch @bobc! Indeed, I recently got a new laptop and set the main language as Swedish, KiCad picked it up as “Standard” (system defined).

If I change the KiCAD language back to English the OpenSCAD import works right away!

The original problem was due to the DXF file using ‘Polyline’ rather than ‘LWPolyline’; a patch has been submitted. The other problem (language settings) needs more thought. DXF should always use the “C” text and numeric environment (ANSI 7-bit character set with ‘.’ for the decimal mark). Preferably we should use the C++11 mechanism for per-stream numeric settings but the DXF code is lib_dxf from LibreCAD and we may be forced to use the older language mechanism which affects all input and output.

1 Like

Just for reference, if you want now there is an other option to design your board edge:
using FreeCAD Sketcher and push the edge directly to KiCad using SteUp
The Sketcher for Getting to Blinky

3 Likes