New way to import DXF outlines to Footprint?

I’ve been looking for a way to import dxf files as a footprint. I have a relatively complicated structure with lots of arcs and bends but all the tools I’ve found that people wrote either fail with cryptic errors or are hopelessly outdated. Can anyone point me to the latest and greatest? Are there any plans on making this a standard feature in Kicad in the future? In my case, it is a microstrip structure so the enclosed lines need to become a fill. Thanks for any help!

Hi,
Using Freecad and the KicadStepUp Workbench could be easier.
https://wiki.freecadweb.org/KicadStepUp_Workbench

I use this method with complex shapes in DXF to create Kicad Footprints.
Create the footprint in DXF format
Open the DXF file with FreeCAD.
Switch to Kicad StepUp Workbench in Freecad
Click to create a Kicad Footprint
You’ll get a Kicad footprint (.kicad_mod FILE).

Best regards.

Oliver

2 Likes

Choose your OS, and then install KiCad-nightly V5.99?

I do believe you when you write you tried all kind of stuff, but there is no information in that to help you further. It is still just a guessing game of what you may have tried and where you get stuck.

KiCad does have import of .DXF and the footprint editor in V5.1.9 does have a File / Import Outlines from DXF File but I do not have much experience with that.

KiCad-nightly V5.99 may have improved import support for .dxf, but you best bet may be the StepUp workbench in FreeCAD, as Olivier_Lesvenan already mentioned.

1 Like

I suppose I did not give enough information. I was fighting this problem for so long today I forgot that it is all new to you :slight_smile:

@Olivier_Lesvenan Unfortunately, StepUp also failed to produce the result I wanted, telling me to"discretize" my arcs. I have an open question with the developers on the github. I think the issue is that the only way to have a fill in the footprint is with a polygon. I’ve written a script to handle this, perhaps after I clean it up I will post it and add it to the long list of dxf helpers that expire soon after their release XD

So to summarize the problem again: I have a dxf file which contains the outlines of my tracks for a 1x8 Wilkinson divider at 20 GHz. It looks like this when I import it in KiCAD:

What I wanted, was a quick way to change the above, into this:

This is challenging because the dxf imports as line and arcs, not as a polygon and as far as I know, there is no way to convert them. The fidelity of the structure is extreme important because it has a significant impact on the RF performance. The traces need to be exactly as in the dxf file with 0 thickness.

Obviously, creating a polygon by hand is beyond tedious and extremely error prone and inaccurate. The script I wrote now simply takes all the fp_line and fp_arcs in the kicad_mod file and seeks to find an enclosed structure and then merges them into one polygon with a specific fill. Should work for other structures too like PCB antennas, couplers, transition, etc -it just needs to be enclosed (otherwise a polygon doesn’t make much sense…) I would love to see a feature like this in KiCAD, the ability to convert a selected set of lines and arcs to a polygon to which you can assign a fill layer.

Thanks for the comments / help!

Hi, from your DXF file, your shape is not a closed contour, but is collection of closed shapes… ATM to convert it with StepUp you should edit your dxf, breaking the shaps and removing internal edges…

I imagine you are obtaining this dxf from a RF sw… you should investigate if there is a more direct way to obtain the footprint with some coding interface…

you may have a look at:


or
1 Like

do you have a repo to access to your script? … I think it could be useful for other RF guys.
It would be even integrated as kicad pcbnew plugin.

Unfortunately the two items you linked are more on the simulation side of things. I’ve used qucs-rflayout but it would not really fulfill my use case. I already have a simulated circuit that works so rewriting the physical model to fit one of these tools is redundant work. As per StepUp, even when I remove all the lines you indicated making it a single enclosed shape I still got the same error. You are correct though, the dxf needs some touch-up before it is exactly what I want.

@maui It is my plan to make it plugin. I have to look at the interface… Currently it does the bare minimum for my needs, no gui. I can update that. If you like, I can send a PR to https://github.com/easyw/RF-tools-KiCAD when I’m done. By the way, great collection of tools! I use them all the time :slight_smile:

1 Like

yes, please :smiley:

1 Like

@maui I noticed you use wx for the gui, is there anything against using pyqt?

@dom11990 kicad c code is based on wx… so I did for py code… other plugins do rely on wx too…
wx is already bundled with kicad python environment on win

@maui It seems that it is not possible to call action scripts from within the Footprint editor, is this correct? Or is there some workaround / trick that I’m not seeing?

@dom11990
unfortunately in k5 it is not possible.
In k6 I’m not sure if it will be available…
Anyway for example a script can be invoked in pcbnew to generate a fp in the same folder where is the dxf file… from pcbnew then the fp editor can be invoked to check the result

The footprint editor has built in wizards for creating certain types of footprints, such as circular pad array’s BGA’s or DIP.

These wizards are started from the footprint editor, and are typically a few pages of python code.

I guess what I’m concerned about is the workflow. I my ideal workflow would be you open the FP Editor, import your dxf, select the lines+arcs you want to convert to a polygon and then execute the action plugin (which doesn’t exist in the FP Editor). As you saw in the dxf file I had, the structures that are imported often require some touchup before they fulfill the requirements of the plugin. It would be nice to be able to use the user interface for this task as it is easy and intuitive i.e. selecting some lines that cause problems and deleting them.

If I invoke the script from pcbnew, the dxf file already has to be perfect, otherwise it will fail. I want to avoid a complicated interface that displays the imported structure and allows editing from the plugin gui. The FP Editor is more suited for this.

If I used the wizard approach, it will have the same problem of needing a already ideal dxf file.

Maybe the way to go would be to set it up as a pcbnew plugin and ignore the whole dxf part. That is to say, if a user wants to convert a dxf in this manner, they import it in a FP, copy it to the PCB, select the structure they want to polygonize and then copy it back to the FP. Seems like an OK workflow, definitely not ideal. I would also need to change the code to actually create the polygon on the PCB as opposed to generating the text in the footprint directly. This should not be a big deal though. Thoughts?

you could import the dxf in pcbnew, select the lines/arcs you want to export as footprint and, through the plugin, generate a fp with line and arcs from the pcbnew objects…
I’ve done a plugin to move objects to a different layer… then you could use that code to extract some tips… in StepUp there is also some code to convert FC lines and arcs to fp format, to get other tips…
the plugin could take this path: convert internal pcbnew objects (from the dxf imported file) to a fp generated by the python code…

Yeah this seems like a viable option. I didn’t know you could import a dxf in pcbnew, I thought only in the FP Editor. For a first step i’ll just have it create the polygon in pcbnew and the user can hand copy it into the footprint they want. Next phase can also automate this further via the conversions you mentioned. Thanks for the tip!

here the repos:
MoveToLayer
kicadStepUptools.py -> def export_footprint(fname=None):

1 Like

@maui I’m having the strangest issue… when I call pcb.GetTracks or pcb.Drawings, Kicad crashes. Have you seen that before? How can I properly debug the script as it is running through kicad?

Ok I’ve made some progress. If anyone is interested in trying it out feel free:

For now it just makes the polygons in pcbnew. I’ll include the export to footprint at some point in the near future. Let me know if you have any issues with it. I used pyqt5, I needed this quick for work so I didn’t want to learn wx :slight_smile:

1 Like

@dom11990
I’ve seen your tutorial and it is nice.
Is your function to create a polygon able to automatically delete internal segments?
image