DXF exporter for mechanical layers of kicad_pcb board

Hi,
I’ve made a dxf exporter for mechanical layers of a kicad_pcb board
“Dwgs”, “Cmts”, “Edge”, “Eco1”, “Eco2”, “F.Fab”, “B.Fab”

the dxf file generated has:

  • single line draw as it should be for mechanical interchange
  • circle and arcs as circle and arcs as it should be for mechanical interchange
  • the pcb layers are written in the same DXF file in different layers and colors
    these options are missing in pcbnew plot (from version 4864)

how to launch:
python kicadpcb2dxf.py -f kicad-board.kicad_pcb

the script doesn’t have any dependencies and it is based on DXF R12 writer from ezdxf library

EDIT
I updated the script adding:

  • footprint support
  • text support (mirror & alignment not supported)
  • courtyard layers
  • dimensions
10 Likes

Just for clarity, this is only the PCB and not any of the 3D models, correct? Because the 3D models are in the other exporter?

@ChrisGammell
thank you for pointing this out…

this is a tool to export 2D mechanical and technical layers to DXF in a way that can be interchanged for mechanical collaboration i.e. to produce a front panel coming from the draw to the laser cutting…
this is a quite common case in which, for simple mechanical panels, it is easier to draw the panel just inside pcbnew, instead of in an external mechanical CAD, using the pcb board and components as reference for the drawings…
laser cutting requires a single line DXF and arc and circles as real geometric curves to get the correct points of the job…

for 3D models and pcb, kicad StepUp is still the tool to be used :smiley:
Maurice
PS I’m implementing a cache to make the conversion to STEP MCAD even faster :wink:

4 Likes

Very cool, thanks! Keep up the good work!

1 Like

@maui, Can I use this to export other layers as well? Thanks!

if you go through the code, you can see you could add i.e. Silk Layers quite easily…
but it is not ready at the moment to convert footprint to dxf, just kicad board files, if this is your goal as in this topic

Impressive.
I ran a quick test, and it converted the design elements and opens in LibreCAD, but I think it is not handling part rotation correctly.

PCB outline and dimensions imported ok.
However, Parts that are 0.0’ import ok, those at +/-90’ appear to have lost the rotation. (Courtyard & Fab layers)
Should be easy to fix ?

Related to above, & also see the other new thread on Footprint to Dxf.
ie can you add other layers too, to allow footprint info export ?
(drill and shapes?)

I developed that script mainly for board edge and drawings… then I add some code for footprints in boards, but really didn’t test it heavily…

if you want to load the footprint with drills, holes, pads and front silk you can just run my kicad StepUp tools and load in FreeCAD directly the footprint…
these tools will not load Eco nor CourtYard or Fab layers…

hoping that could help …
Maurice

I do not have an immediate need, but I see others asking so I presume they want to either harvest KiCad footprints, or check/modify/create 3D externally.

The inbuilt DXF plot ‘sort of works’, but checking that, it outputs segments on circles/pads, but if you enable Drill marks then it will export a circle or slot as a more correct DXF entity. (Not that useful for someone wanting pad centres, or pad sizes.)

Inbuilt DXF plot does seem to do a nice job of thermals, and could be used for PCB Copper tooling flows.

[quote=“maui, post:1, topic:2885”]
Hi,
I’ve made a dxf exporter for mechanical layers of a kicad_pcb board"Dwgs", “Cmts”, “Edge”, “Eco1”, “Eco2”, “F.Fab”, “B.Fab” [/quote]

Thank you very much for this tool! The *.dxf files it produces are definitely superior to those produced by KiCAD’s “DXF Export” feature.

I fumbled around for a few hours before I got the Python program to run, from the Windows “CMD” window. Is there a way to run it directly from the “Scripting Console” in PCBNew? (Especially if it could use the board file currently loaded in PCBNew as the default input file.) The suggestions I found in the thread “Tutorials on python scripting in pcbnew” at Tutorials on python scripting in pcbnew didn’t seem to help me.

I modified the Python script to include the “Margin” layer among the outputs. If I had a suggestion for future improvements, I’d ask for either some way to include only specified layers in the output file, or a series of output files, one for each layer in the input file.

Thanks again for this useful tool!

Dale

1 Like

for example you can put a batch file in the same folder where you have your board and then click and drag your kicad_pcb file into the batch file
here a batch example

SETLOCAL ENABLEEXTENSIONS
SET path_to_kicad_bin=“C:\kicad\bin”
SET path_k2dxf_script=“C:\myTools”

%path_to_kicad%\python %path_k2dxf_script%\kicadpcb2dxf.py -f %1
REM pause

start “” %~p1%~n1.dxf

uncomment ‘pause’ to check if the script is running correctly

EDIT:

the output dxf file has already separated Layers, one each kicad layer… so it really easy to hide/delete what is not desired

1 Like

Hi Dale,
finally at least in Nightly it is possible to run a script from within pcbnew
Then I updated some of my scripts to run as a plugin:

there you can find:

they both use the currently loaded board as input file

2 Likes

I see there are two patches for DXF that will recover the old method to export mechanically corrected lines and arcs
[FIX BUG] pcbnew: plot dxf draws 2 lines instead 1 with the right width
[FIX BUG] pcbnew option to export text as editable text when plotting DXF
hoping those will not be lost…

Possible Incompatibility with AutoCAD??

[quote=“PCB_Wiz, post:9, topic:2885”]
I do not have an immediate need, but I see others asking so I presume they want to either harvest KiCad footprints . . . . [/quote]
I guess I am “harvesting footprints”. I’m working with a mechanical guy to position circuit boards, connectors, LED’s, etc, within an enclosure. We are neo-Luddites, doing most of our day-to-day mechanical CAD work in 2-D tools - specifically, AutoCAD. (I don’t know the version, but it’s fairly recent.) We also use the paleolithic technique of paper cutouts to create mock-ups, verify fits, assess the visual impact of design concepts, etc.

I used the DXF Export tool from @maui to pull layers out of my KiCAD project and create *.DXF files. I then used LibreCAD to pick off particular features and information, saved the results in a *.DXF file, and sent the files to the mechanical guy.

AutoCAD can not open the *.DXF files, neither the version exported directly from KiCAD (using @maui’s tool) nor the version saved from LibreCAD. We tried saving in other versions of *.DXF (available in LibreCAD) without success. We tried some file recovery tools in AutoCAD, without success.

Has anybody else experienced this incompatibility? Any hints or suggestions?

I should mention that all of these *.DXF files open without problems in LibreCAD, and also CADStd, and also Adobe Illustrator, and can be imported back into KiCAD . . . . so I suspect that AutoCAD is being picky about something in the files but I don’t know where to begin looking for the incompatibility.

Dale

(Note to moderators: If this is unacceptable necromancy of a deceased thread, spank my typing finger and move it to a new thread. In my opinion, the post fits here because it refers specifically to the tool created by @maui .)

If I remember correctly, in AutoCAD you have to Import DXF files and not just Open them…
Which errors is your friend reporting when trying to open the dxf file?

Have you tried with the AutoDesk DWG TrueView viewer to see if you can Import your DXF file?

Moreover DWG TrueView can save the file as DWG and you can then pass this file to your mechanical guy…

An other free program that can open DXF and save as DWG is DoubleCAD XT v5

The two solutions above work only in Windows…

For Win/Linux/OSX you may need Teigha software (free too)
https://www.opendesign.com/guestfiles/TeighaFileConverter

1 Like

Thanks for the suggestions. I’ll investigate them next week. Converting the file(s) to *.DWG format sounds like a good experiment to try, and I think Teigha can do the conversion. That still makes a rather complicated, rambling, process to simply move information from me to him.

As I recall, the AutoCAD error referred to an “invalid entity in file” or a similar phrase. My mechanical counterpart tried a lot of stuff with AutoCAD - various “recovery” and “repair” utilities - I don’t specifically remember if he used “Open” or “Import”. (If he made the wrong choice between “Open” and “Import”, wouldn’t he get something like a “File type not supported” message? I don’t think he mentioned encountering anything like that.) After wasting most of a day, we “solved” our immediate problem with a pencil sketch and a bunch of hand-copied dimension values. Obviously, that’s not an acceptable process so I’ll look into your suggestions.

Dale

This is the issue that DFX exporter is currently tough to handle. printer offline fix helped me to get the solution of this.

How is the printer related to the dxf export? Are you sure you had the same problem as described in this thread?

2 posts were split to a new topic: Utilize easyw/kicadpcb2dfx