I wrote a program to automatically update PCB refdes and back annotate to the schematic

I have spent the past week or two writing a command line utility called RenumberKiCadPCB.

It allows you to automatically renumber all the reference designators on the PCB then it goes back and updates the schematic accordingly.

It is sort of an independently developed update of Kren, which does not appear to support new KiCad file formats.

There are a a choice of rules, including separate sorts for front and back. It is very flexible with a number of options including Front and Back prepend strings, etc…

I have carefully tested the software on my own designs but the true test is when other people will use it.

The source code as well as a Windows 64 executable (Linux is coming) is posted here https://documenteddesigns.com/kicad-pcb-renumbering-utility/

There source is written in very basic “c” and is available as a single source file to make it easy to make. So you should be able to easily compile it on any platform such as Linux for which there is a gcc or equivalent compiler.

Let me know what you think.

2 Likes

Thanks. I tried using the other script but I could not get it to work. Not only does he require you load his own fork of Kicad Python but I am pretty weak on Pyton so I couldn’t debug the problem.

So I tried and tried and could get it to work at all and realize I could probably write my own standalone, fully featured utility in less time so I did.

Please let me know if you have any questions regarding the source, etc…

Brian Documented Designs

A doubt, renaming refdes means the annotation function in the eeschema right?
if so why do we need a separate script/program ?

Hi @DocumentedDesigns, I’m the author of that script. I would be happy to help if you let me know what was the problem?

By the way someone forked my script and removed dependency on kicad-python: https://github.com/cculpepper/kicad-python/blob/master/examples/pcbannotate.py

I haven’t tried it but it should work from the kicad’s python terminal without any dependency.

When you do annotation in schematic its done according to symbols position on the schematic. To me (and some other people I guess) this is not very useful when soldering the PCB.

This program allows you to do annotation in the pcb, so that components are sorted according to their position in the PCB. When you are looking for, lets say, component named R1 you know that it should be on the top side of the PCB and very close to the top left corner.

3 Likes

Usually you place the components on the PCB then you want them in order (top to bottom right to left). Then you move that numbering scheme back to the schematic so when you want to locate, for example, R24 on the PCB you know where to look.

This not only renumbers the PCB automatically it back-annotates the schematic.

I forgot to mention I updated the files at https://documenteddesigns.com/kicad-pcb-renumbering-utility/ to include the instructions to make the program under linux and to correct two warnings which gcc reported which did not show up under Windows/Eclipse and correct a minor bug which resulted in the run time being miss-reported if the process was aborted.

1 Like

This is what I get when I run the Python Script I mentioned

PyCrust 0.9.8 - KiCAD Python Shell
Python 2.7.10 (default, Jul 8 2015, 15:10:39)
[GCC 5.1.0] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
import sys
sys.path.append(“C:\BP Sync\Downloads\kicad-python-master”)
execfile(“C:\BP Sync\Downloads\kicad-python-master\examples/pcbannotate.py”)
Traceback (most recent call last):
File “”, line 1, in
File “C:\BP Sync\Downloads\kicad-python-master\examples/pcbannotate.py”, line 31, in
from kicad.pcbnew.board import Board
File “C:\BP Sync\Downloads\kicad-python-master/kicad/pcbnew/board.py”, line 24, in
from kicad.pcbnew import module
File “C:\BP Sync\Downloads\kicad-python-master/kicad/pcbnew/module.py”, line 26, in
from kicad.pcbnew.pad import Pad
File “C:\BP Sync\Downloads\kicad-python-master/kicad/pcbnew/pad.py”, line 30, in
class PadShape(IntEnum):
File “C:\BP Sync\Downloads\kicad-python-master/kicad/pcbnew/pad.py”, line 34, in PadShape
RoundedRectangle = pcbnew.PAD_SHAPE_ROUNDRECT
AttributeError: ‘module’ object has no attribute ‘PAD_SHAPE_ROUNDRECT’

Oh, it seems that some additions I made, requires a newer version of kicad. I’m guessing you are on the stable version. Thanks for feedback.

I tried this new forked Python version from the link quoted, with some minor quick edits to run on the loaded-design file, and it gives this from KiCad’s command -

execfile("C:\KiCad_Python\PCB_ReAnnotate\pcbannotate.py")
Re-naming Q1 -> Q101
Re-naming Q4R44 -> Q4R101
Re-naming Q3 -> Q102
Re-naming U1 -> U101
Re-naming U2 -> U102
Re-naming U2R34 -> U2R101
Skipping: Q4R44M.
Skipping: U2R90M.
Re-naming Q2 -> Q103
Skipping: U1MV.
Skipping: U1M"VJ.
Skipping: U3R34M.
PCB annotated.
execfile("C:\KiCad_Python\PCB_ReAnnotate\pcbannotate.py")
Skipping: Q4R44M.
Skipping: U2R90M.
Skipping: U1MV.
Skipping: U1M"VJ.
Skipping: U3R34M.
No changes were made! This is normal if your components were already named in correct order.

Seems to be as expected ?

What version of KiCad was this ?
I think that ROUNDRECT is a fairly recent, new PAD SHAPE.
Could be that older installs do not understand that ?

Yes, thats how it works.

By the way I did some further changes to cculpepper’s version. Now it works when called from kicad’s console and I also changed numbering scheme back. It should start naming components from number 1. Here is my fork.

The version of Kicad I am using is V4.0.2

You are sort of hijacking my thread …

Strange, I would expect that to be ok. My build of June 19th is only slightly newer.
Could your Python side be older ?

( The thread is about PCB renumbering, so code that does that looks to be on-topic ? )

I started the thread with the hope people would test and verify my richly featured software solution.

Question for me would be how to get this sort of stuff into the main branch or as some sort of button into the GUI at least?

@Joan_Sparky I had filed a feature request for running python scripts from the GUI, but it didn’t get any attention from the devs.

@DocumentedDesigns I’m sorry we have disappointed you in that regard. My intention were to help you. But I want to mention that; nowadays the preferred way to share an open source application is to upload it to a public site such as github or bitbucket. I’m pretty sure that would increase the interest in your code.

1 Like

I asked something similar @ kicad developer list, but it seems they just don’t care about a more friendly GUI for executing python scripts…
https://lists.launchpad.net/kicad-developers/msg21500.html

a second thing that I would like to ask is the ability to have a button
to be configured to execute a python file as if it would be invoked in
pcbnew python console…
That would make the way to execute a python script inside pcbnew more
human than geek…

1 Like

Things can be added to KiCad that were not developed at CERN, but you had better code it to their software standards and still expect a long wait

1 Like