Kicad V5 portable project


#1

Hi

Has anyone started to experiment how to make V5 projects portable. Especially schematics. With new symbols handling (which successfully solves library priority issue) renaming project-cache.lib and including it in the project symbols library table does not result in a project being portable.

Thus person opening my project has to have the same libraries as I have. Even more, the libraries have to go under the same Nickname in the symbol library table.

Is there a way to modify project schematics and/or project-cache.lib to make it portable?

For example the symbol is referenced in the .sch file with the L power:GNDD. The same symbol is placed in the project-cache.lib as DEF power_GNDD #PWR 0 0 Y Y 1 F P

Thus I could parse the .sch file and in symbol reference replace colon with underscore and prepend cache: to it (assuming project-cache.lib goes under nickname cache).

Does this make sense?

Obviously reversing this is trickier as library nicknames and footprint names can have underscore in it. Removing cache: is easy but choosing which underscore to replace with will be tricky. Maybe grab hold of system and project library table and try to fit the names to the ones available from the library? What to do if transformation is not 100%. Abort it or do what can be done and leave the rest of the symbols to be grabbed from cache?


Eeschema automatically loads latest symbol from library
#2

Yes of course, modifying the schematic is possible, as well as reversing the process, which is why I previously suggested using a script to do those things.


#3

Yes, the script seems the way to go, I am just asking around if anybody has already went down this path and if there is anything special to handle which I might miss. I’ll probably start on the script in the following weeks hopefully wrapping it in action plugin.


#4

If you modify the schematic file on disk while KiCad is running (whether by editor or script), the schematic should be first closed in KiCad, then reloaded after the script has run.


#5

This is the exactly the information I was looking for. I would not even consider to think about concurrent editing issues. Thank you.


#6

@MitjaN
Are you also considering making 3D models portable? AFAIK KiCad doesn’t automatically cache the 3D models (nor embed them into the board file like it does for footprints), so that is something that a script would have to do.

My guess would be:

  • Create a folder in the project path for the 3D models that can be resolved within KiCad in the %{KIPRJMOD} path. Like, for example, “%{KIPRJMOD}/packages3d”
  • Scan through .kicad_pcb file and for each 3D model copy the linked model from the source to the local folder. If the source 3D model is identical in both path and filename to one already copied, do nothing. If the path is different but the filename is identical to one already copied, make a new (unique) filename.
  • Change the path (and filename if necessary) of the 3D object reference in the board file to point to the local copy in %{KIPRJMOD}.

The above may be able to be done in the existing Python API of v5.0 Pcbnew, but I don’t know for sure.

I can imagine that the collision detection of identically named footprints could get a bit complex, but that’s why we write scripts to deal with those complexities for us. Thinking about it, I don’t know how v5.0 EESchema handles identically named symbols from different libraries when building the project cache library…


#7

I’ve got the schematics mostly handled, but I will need some time to test it before I release it

And I just got 3D model archiving and relinking working. But the main issue is that python interface does not expose module 3D settings (I’ve raised a bug report) so I implemented it outside of pcbnew API. This will also need some testing especially as I’d like to release this as an action plugin, as it makes much easier for use across platforms and with tech-unsavy users.

And I don’t have a slightest idea how pcbnew behaves when somebody else is changing the file ,which is already opened, in the background. I’d like to find a safe way of handling this, but I am not certain it exists.

At the moment I am thinking along the lines:

  1. Save board item (might go thorough pcbnew python API or via wx API)
  2. run the plugin
  3. force the pcbnew to load the board or kill the pcbnew

I admit this is probably not the safe way to do it so I’ll spend some time banging my head against the wall trying to find clear solution.


#8

I have an idea that is more of a kludge. If it is possible to query in python if pcbnew is open (or if the board file in interest is open in pcbnew), throw an error to the user telling them to close pcbnew before running the script and then exit.

Doubt this would work on a board file on a shared drive that is open on another computer, unless kicad does some sort of file locking that I’m not aware of.


#9

As I plan to release this as an action plugin pcbnew has to be opened, as it will be run from the pcbnew.

I found a way to emulate keypress events, so I can force save a board, execute my code and then exit the pcbnew. It is not ideal, but it is safe.