Edit multiple component fields using KiField

Hello all, I am a new user to KiCad. I chose this software to keep all my work open-source, yet take advantage of a powerful tool. So far I am pretty happy.

Editing multiple components with KiCad can be incredibly tedious. I recently found the KiField Python Package and this certainly is the way to go. I created two batch files: one for exporting, and then I can edit the csv file, and the second for importing, and deleting the now defunct csv file. This way I can ensure I don’t overwrite values that I manually set in eeschema.

My Question is this: I created a new field in the csv file called “mfg” for manufacturer part number. I then changed the name two “PartNumber”. Now every component has two fields. It seems that removing columns from the cvs file does not removed the field from each component. Does anybody have a solution for this?

Export csv:
kifield -x TopLevel.sch -r -i Scripts\exportedCom.xlsx
Import csv:
kifield -x Scripts\exportedCom.xlsx -r -i TopLevel.sch
rm Scripts\exportedCom.xlsx

If I recall, KiField is tries to be as inherently safe as possible and therefore will only updated the per the cvs columns listed. It never deletes information. I had a legacy schematic that had parts with a mix of fields, with some fields that were dead as you have. I believe I opened up the .sch file(s) in a text editor (VIM) and did a global find/delete that blew away all the lines containing the field name I no longer wanted. As usual, back everything up before trying anything.

2 Likes

The KiField documentation has a section titled “Removing Fields from a Schematic or Library”. That would be the section to read if you are interested in removing fields from a schematic or library.

4 Likes

Brilliant. obviously I should have re-read the directions before posting.

Thanks!

Ah, I mis-read that section. To be clear, that doesn’t just clear the fields, but removes the field from every part’s properties in the schematic?

I need help with Kifield too. I know there is a command to extract the fields fromschematics or library and place them in a CSV file and reverse.
Here is my command to extract from csv file and place to library.
kifield -x E:\Work\1New_Kicad\Lib_SMDes\fields2.csv -i E:\Work\1New_Kicad\Lib_SMDes\Lib_SMDes.lib
But I need that some info in fields was overwrite to new info,
–overwrite, -w Allow field insertion into an existing file.
But I dont know how to wrote the command, Im not familiar with python, please help me on my example above.

Just place a -w at the end of your command. That will overwrite the values in the .lib file with the ones extracted from the .csv file.

1 Like

It was worked well, but on next time, I can not edit my library file. I work only one way, from lib to csv, dont want to do back import with -w command or without.
My commands are same. What could gone wrong ?

Still have a problem
I use this commands:
kifield -x E:\Work\1New_Kicad\Lib_SMDes\Lib_SMDes.lib -i E:\Work\1New_Kicad\Lib_SMDes\Lib_fields.csv ( then edit it)
kifield -x E:\Work\1New_Kicad\Lib_SMDes\Lib_fields.csv -i E:\Work\1New_Kicad\Lib_SMDes\Lib_SMDes.lib -w

And it not works for my Lib_SMDes.lib, nothing changed

What Im doing wrong?

I found out what was wrong, seems for some reason its not working with .csv files. I tried with .xlsx and its works fine