Give my schematic AND pcb ONE version ID?

Apologies for the clumsy topic title…

I’m looking for a way to “set a global variable”, and have the value there appear on my schematic and on my pcb, both onscreen, and when manufactured.

I want that so that there’s a foolproof way of knowing how “old” anything I’m looking at is… a version ID.

I have a workaround, but it seems pretty lame: I dedicate some component of the circuit to doing double duty: It will be a “real” component, one that would be there anyway… and I “highjcak” that component’s value, and enter my version ID there.

There must be a better way?

Yes! I know I can (File | Page Settings) establish or update a value in the “Revision” field… but that won’t carry across from the schematic to the PCB, will it? I’ve only grasped that as a way to note a revision date/serial on the drawings… and I would have to make a change in TWO places (not hard, but easily fluffed) if I wanted to be able to rely on the revision information to tell me which of two printouts was older… wouldn’t I?

Even if that’s acceptable, how do I get the page’s “revision” information to appear in the silkscreen, without another manual edit?

Maybe I get you wrong but from what it sounds like you should simply create a component in your library with a corresponding module.

That’s what your workaround does, only would you actually be able to control size etc. better and have no unwanted drawings and pins there.


How is your python? While I hadn’t looked at the KiCad pcbnew scripting documentation prior to this, a script can access the revision from the title block with pcbnew.TITLE_BLOCK.GetRevision() and then presumably if you have a nicely formatted footprint defined for the job you should be able to change the Value field (with pcbnew.MODULE.SetValue()?) and have that appear in the silkscreen.

It appears feasible if you just want to version stamp the PCB to get the script to create a text element in the silkscreen at a known location relative to the lower left corner too.

I’ve not done any scripting for KiCad yet but at a quick look around the documentation it looks like all the elements you need are exposed to the scripting language for you to exploit should you be keen.

Cheers ! Geoff

Thank you!

Scripting: Sounds like a great answer… if I knew enough! I know a bit about programming. With the scripting answer, I’m guessing I add a bit of custom code somewhere, and then something triggers it somehow? (A few bits of learning needed, as you can see! If someone can give some pointers towards this solution, maybe he/she would be kind enough start a new thread, title “Add a feature” or somesuch? Or post a URL in this thread to the “how to” that must be out there somewhere, if only I could devise a suitable search phrase?

Custom component: That looks more immediately do-able.

Here’s how far I’ve got with it… and what I say below applies whether I “mis-use” the field of a component like a resistor (the easy answer), or of a component created for the purpose (the right answer, as soon as a newbie can make his own components… a “basic” skill, more than worth the effort to learn!)…

If I put the version ID in a component’s value, it flows through from schematic, where I set it for the whole project, to everywhere else effortlessly. But, unless I’m missing something, I have to have all of the components’ values printed on my board to get any of them? I don’t think I want that!

If I put it in a component’s reference, that works better in terms of the result… I am quite happy to have all the references on the PCB.


Each time I change the component’s reference field, unless I am missing something (?), I have to…

Regenerate (from eeSchema) the netlist
Re-run cvPCB
– Assign a footprint to the “new” component
Go to pcbNew.
– Delete the “version” component currently on it.
– Re-read netlist
– Move the version component to the right place… again.

Have I missed ways to streamline that?



I had the good fortune to spend a lot of time in waiting rooms today, and used it to do a bit more reading. I think I understand what you’re looking to achieve and it doesn’t need be as complex as you suggest. If you just want silk on the board that can be done with a text element. If you name that text element something memorable/unique that’s never to be the name of a component in your design, you can look for it by name and, if present update the value and if not, create it. That means you don’t need a footprint. Not only that, it’s unchanged by re-reading net files, and you can even move its position and size manually and the script won’t reset things. Unless you specifically want it to.

However, scripting only currently extends to pcbnew. The version number in your schematic and your board design aren’t linked, and there’s no way presently to read or interact with anything in eschema from the python API (at least from what I read).

The good news though is the .sch file is plain text, and the info you need is right there. Rev “0.9” is in the .sch of the project I presently have open here. So you could open the schematic file directly, parse that value, and propagate it to the board revision as well as a text element on the board. The revision of the schematic would become the source of all truth. You’d just need to remember to run the script in pcbnew.

While you can’t directly find the schematic filename in Python, you can find the board filename.

pcb = pcbnew.GetBoard()
print pcb.GetFileName()

The above prints out the full pathname of your board file - so replacing the .kicad_pcb suffix with .sch gets you there I think:

pcb = pcbnew.GetBoard()
print re.sub(’.kicad_pcb’, ‘.sch’, pcb.GetFileName())

At least until there’s a change in the file naming convention in KiCad - but by then hopefully you’ll have the ability to access eschema directly in Python and you’ll have written a more elegant script for the job.

What would be great is if you could have the python plugin trigger automagically when you export the gerbers. I’ve not yet read enough to know if that’s in the capabilities presently though.

Cheers! Geoff

A small test

#!/usr/bin/env python
import sys
from pcbnew import *

# used to locate revision string in schematic data file
import re
p = re.compile('^Rev "')

# current open board instance
pcb = GetBoard()                             
# open related schematic file                       
sch = open(re.sub('.kicad_pcb', '.sch', pcb.GetFileName()), 'r')    

# parse schematic data file
for line in sch:
    m = p.match(line)
    if m:
        Version = line

# for the win
print Version    

results in

Rev “0.9”

So that’s the bit where the revision is read from the schematic file (confirmed in this limited sample size of one).

Cheers! Geoff

Oh dear. Will I never learn to be content with what I HAVE?

Spent the last hour playing with the “simple” answer.

Following might “do” for me…

I’m going to accept that I “need” to have all of my component references appear in the silkscreen of my PCB.

Once and for all, created in a .lib a component: VERBYREF ("VERSion for project entered BY altering item’s REFerence field.) No pins. Default value a little tricky: Put what you like… but remember that it will appear in one of the cvPCB columns, so don’t go mad. (KiCad puts it as upper case in some places, regardless of how I start it.)

Once and for all, created a .mod footprint: NoPin. With, yes, no pins (!). CAN call that “NoPin” and have the name survive in mixed case where I want it.

Once those are in place, forevermore I can just…

1st pass… Put a RefByVal component in the schematic.
Make it’s VALUE something like “vers-12Feb-15v1”… note:
no spaces in that, and last character a digit.

During cvPCB: associate that with the NoPin footprint.

Subsequent passes: Revise component’s value on the schematic. Re-save netlist

Close (if open) and (re)open cvNew
Assign NoPin to the “new” component.
Save. (Perhaps not needed. Maybe automatic.)
Close cvNew, so I don’t forget!

Go back to pcbNew window. Delete the old
version-ID-giving component. Read netlist. Move
“new” version-ID-component to where I want it.

A digression: Having board edges set up… even if they are provisional… may help by putting to-be-placed things in a more convenient place that where they go if there is no board edge defined. Or maybe I tweaked something without noticing while setting up NoPin! (^_^)

Is it the same with the latest Kicad versions that the board revision or the drawing numbers can’t be extracted using python APIs??

In general reviving old threads isn’t recommended here.

The unstable development version 5.99 has text replacement variables (exactly what the first post asked for). The latest stable 5.1 doesn’t.

Indeed, V5.99 has text replacement.
I also found the workaround from ambhibious, of using a separate schematic symbol and custom footprint a good idea.