Place mounting holes via coordinates from csv file

Hi all,

I have a csv with mounting holes for a pcb and there x and y coordinates.
Is there a way to auto place these components in pcb new?
If not i would have to place all these by hand and for example edit x and y location.

thanks in advance

@Derhaegr How many holes do you need to place? Honestly I don’t think it would take this much time to place them manually, unless you have them in the tens or hundreds.
Make sure to lock them once you’re done.

Hi @eeintech,

Wel its not your conventional board design and i have to design 3 every year or something like that.
I think about 80-100 holes per board.

Maybe you could script it in Python?

Was going to suggest a similar option, given kicad_pcb are fairly easy to read text file, your could read it out and replace X-Y coordinates for all mounting holes using the data from your CSV. Python would do well for this.

I was thinking the same thing.
I tried to copy paste this in kicad_pcb but did not work. I figured it would be best if i placed them all and replaced the X and Y.
I don’t think something like this allready exists because its very specific so i think i need to write from scratch.
I don’t really know Python so i might do it in something else

You don’t have to parse the .kicad_pcb file that’s done for you when you use the pcbnew API in your script. Then read the CSV file (there are Python classes for this) and add the hole objects at the positions indicated. Naturally you have to align to the board’s origin.

I just did a simple test.

Started an empty project, started Pcbnew and put a footprint of a hole on it with o (ASCII 111 or 0x6F, you know the letter between n and p in the alphabet).

Then I closed KiCad and opened the PCB in a text editor.

  (module MountingHole:MountingHole_4.5mm (layer F.Cu) (tedit 56D1B4CB) (tstamp 5F3EA95D)
(at 161.1 80.4)
(descr "Mounting Hole 4.5mm, no annular")
(tags "mounting hole 4.5mm no annular")
(attr virtual)
(fp_text reference REF** (at 0 -5.5) (layer F.SilkS)
  (effects (font (size 1 1) (thickness 0.15)))
)
(fp_text value MountingHole_4.5mm (at 0 5.5) (layer F.Fab)
  (effects (font (size 1 1) (thickness 0.15)))
)
(fp_text user %R (at 0.3 0) (layer F.Fab)
  (effects (font (size 1 1) (thickness 0.15)))
)
(fp_circle (center 0 0) (end 4.5 0) (layer Cmts.User) (width 0.15))
(fp_circle (center 0 0) (end 4.75 0) (layer F.CrtYd) (width 0.05))
(pad 1 np_thru_hole circle (at 0 0) (size 4.5 4.5) (drill 4.5) (layers *.Cu *.Mask))

)

Then I copied that block of text 3x in the text editor and changed the first 2 lines in the copies:

(module MountingHole:MountingHole_4.5mm (layer F.Cu) (tedit 56D1B4CB) (tstamp 5F3EA95D)
(module MountingHole:MountingHole_4.5mm (layer F.Cu) (tedit 56D1B4CC) (tstamp 5F3EA95E)
(module MountingHole:MountingHole_4.5mm (layer F.Cu) (tedit 56D1B4CD) (tstamp 5F3EA95F)

(at 161.1 80.4)
(at 171.1 80.4)
(at 181.1 80.4)

The I opened the PCB again in Pcbnew and I had 3 mounting holes, with a horizontal distance of 10mm between them.

The second line are the coordinates of the holes.
The first line I changed has the “tstamp” value, This “timestamp” (which changed to an UUID in the latest KiCad versions) has to be unique for each footprint. This timestamp is the normal connection between schematic symbols and PCB footprints.

As you can see I also changed the “tedit” value
I’m not sure what that value is used for.
In another test where I placed 2 mounting holes in a .pcb file the “tedit” values were identical, so apparently you do not have to change those.

So in a very simplistic external script you can take a PCB file, split it in some text blocks and then concatenate these blocks into a new file.

When you want to do the scripting from within Pcbnew you have more advanced functions available, but you have to figure out how the scripting interface works. This way is probably also more robust between KiCad versions, where the file format changes. But newer KiCad versions should always be able to read old KiCad files.

There used to be a link to a text file on the kicad-pcb.

Link to Documentation of KiCad’s file formats has been broken for half a year or so, but I just checked again and it has been repaired. You can find it at:
https://kicad.org/help/legacy_file_format_documentation.pdf

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