EEschema component timestamp (id)


#1

Hi there,

I created a python script that creates a parametric keyboard matrix with diodes and switches for EEschema. It works very well. But something really bothers me and I would like your input!

The identifier that is created for each component is based on a timestamp that has very low granularity (seconds). The way I currently handle this: I get the current timestamp and for every component I create I increase this timestamp by one second to prevent duplicate Id’s. So if I create a 10x10 matrix with 100 diodes and 100 switches I need to wait, in theory, 200 seconds before I can create another unique set of timestamps.

I noticed when I copy a component in KiCad it just adds 6 seconds between component timestamps.

This all feels a bit weird and I’m not sure if i’m missing something! I hope simebody in this forum has more experience with parsing EEschema files!

Thanks in advance,

Arjen


#2

Originally, it might of been an actual timestamp, but really it is now just a unique id. I don’t think anywhere it is treated as an actual time. Possibly the only place it matters is when importing netlist to pcbnew, the unique id might need to be a greater value to indicate a component has changed.

Perhaps a dev will be around to give the definitive answer !


#3

Bob is correct; they’re just UIDs at this point.

We’ve been discussing changing them to GUIDs to further prevent collisions, and to remove the confusion around calling them timestamps. That will likely get done in 6.0.


#4

Thanks so much for answering. I figured that that they do not have to be timestamps. Maybe my question should have been: How to avoid collisions? Should I check all ids for collisions myself? Just out of curiosity: how does KiCad handle this? I noticed that if I append the same schematic into itself, it creates new IDs.

p.s.
Is a plugin API still in the pipeline, than I could just ask KiCad to create components with GUIDs for me :wink: ?

Thanks so much!


#5

Kicad starts with the current time and keeps a static variable for the last time used. If the current time is ever less than or equal to the last time used, it uses the last time + 1.

So it’s essentially the same algorithm you’re using.

If you start with time() * 1000 for each run it will give you a lot more room between each (real) second, and keep you well away from anything Kicad might create. (This assumes Python has more than 32bits of resolution for times on your platform, but that should be easy enough to test.)


#6

Thanks for helping me out @JeffYoung!