Getting started using Python Scripts

I know why now, 4.0.7 is not detected fully from PyCharm, but 5.0.2 is ok for import pcbnew.
But import sys, or import math are not detected correctly.

For me, I not only point python interpreter to KiCad, but also, I need to include a source tree from <KiCad_Install_Dir>\lib\python2.7. That seem to work.

The bad news is that I am an analog/power design engineer for whom all of this Python script stuff is quite foreign. To me, Python is a snake, and script is my unreadable handwriting. I gave up on that and I print.

The good news is that without really knowing what I was doing, I was able to run a reasonably structured BOM on the first try using bom_csv_grouped_by_value_with_fp.py which came with the KiCad install.

My question is that the “description” field (the 6th column) which is output by that BOM is a lot of wrong information for my parts; I cannot find where it resides so that I can edit it? editititititititi I do not see it in my symbol library or in component properties in Eeschema. (???)

@BobZ. You can try download my python script, and run BOM generator with bom2csv.py. When you edit it in excel for correcting the problem. Then you can run c:\program files\kicad\bin\python.exe bom2sch.py … so update your schematic with the corrected values from the csv bom. You can find and download my thing here: Back import custom fields

Thank you, nhatkhai. I have downloaded and run your script. I am not sure that the BOM produced by your script is any closer to what I want than the BOM produced the script which came with KiCad. I have no desire to learn programming right now. I am trying to correct the source information for that BOM but I do not know where that source information resides? I doubt that the source information is contained in the script. If that were the case then a new script would be required with each BOM change.

You problem get to abstract to me now. I’m not sure what is your exact issue. My be if you can share a BOM or schematic file or image to help me understand what is it about.

Thank you.

Here is a view (in Eeschema) of properties of transistor Q10:

I tried to copy-paste the .py file but cannot. It is _bom_csv_grouped_by_value_with_fp.py
which came with KiCad

Now here is a screenshot of a portion of the BOM which was generated:


The text:
"20V Vds, 1.5A Id, N-channel MOSFET, SOT-323" is a mystery to me. Where did it come from?

I am saying this is a Dpak but some description field somewhere says that it is a SOT-323. How do I edit the source of that information? ( I want to edit the source, not just the BOM.)

Where is this information (inside red ovals) located? It is not in my .dcm file.

I believe that come from the default value of symbol library. This is why some time I decided that my script try to not extracting that information. This information is irrelevance, and can be overwrite when you define the description field for that particular part on your schematic. Or you can correct that, and run my bom2sch script. This should push the new value in description column (if you corrected in csv file), and push them into each part in your schematic. Then next time you re-generated bom from what every scripts (even with mine bom2csv), you should see it been corrected. Also, you should see the description filed defined for each part from eeschema program too.

(ADDITION EDITED) If you still not like run the python script from the cmd line for bom2sch, then you will need to do manually like I mentioned. Depend on how many part you needed to correct. Another way is using the Kicad 5.x version BOM manager tool from one of the drop down menu. That would avoid you to run the script. It is up to you.

Thanks again nhatkhai

I used Tools>Generate bill of materials from Eeschema. That asks me for a plugin which had me stumped for a while. I think you are posing one possible solution. But it feels like it avoids the bad data which is residing somewhere instead of correcting the bad data. I am no programmer and I could be mistaken, but I would like to get another opinion to see if I can fix the bad data somehow…

If you just want to edit your symbol description go in symbol editor, edit->Properties (there is corresponding toolbar button too, looks like op-amp with a gear in 5.1)

It will be in .lib file then.

My solution (under Protel) was to take from BOM only:

  • number of elements: 5
  • their symbols: R1, R3, R7, R8, R9
  • their value: 1k
    I copy such BOM to second page of my LibreOffice spreadsheet and all neded values are filled from the first page which is my database of used elements.
    That way I have all such informations in one place, see and edit easily.

With KiCad I will also get footprint from BOM. Thanks to that I will have 1k in different footprints (til now I had 1k and 1k_4 elements). I have checked that spredsheet can serch for text being a concatenation of texts from two columns.

People here helped me to modify bom_csv_grouped_by_value_with_fp.py to get what I wonted:

Another way is use KiField script to extract, correct, and push back into .lib, .dcm, .sch file individually.

Thank you qu1ck.

This information was certainly not in the .lib file, and it was no longer in the .dcm file because I had removed it.
The puzzling issues:

  1. I am using version (5.0.2)-1 and cannot find this gear icon; I would appreciate a screen shot.
  2. Yesterday I was still getting this wrong information in my BOM in spite of having removed it from the .dcm file. I am pretty sure that I closed and reopened KiCad and this was still the case
  3. After turning my computer off last night and on this morning the information is now coming up correctly.
  4. When I point to a copy of the .py file in my own folder I now do not get the csv output. For some reason I have to use the .py file which is located in the program files folder. (In neither case do I get a .csv dot extension of the filename. I had to add that.

Hi, nhatkhai

Please tell me about kifield script; where do I find it? How do I run it? I mentioned elsewhere here that for some reason the next day after editing my .dcm file the description information appears to be corrected. But it did not see that yesterday. I have to figure out what I need to do so that my schematic gets updated by my .dcm file edits. Also the “description” field is not even visible in the symbol properties so that does not seem to help. Looking for a screen shot of the “gear” in Eeschema in case that offers any other options.

You will need to again run these from cmd line. But I though you don’t want to. He is the link:

IMHO: This info are insignificant. Your BOM should be the source of true information for your design. Using schematic, symbol libraries storing them for me only to help tracking, and start eaiser. But I would not bother to change those in library, they use for tracking where the symbol come from. Not for your generate BOM.

Hi, nhatkhai

I think that to some degree it is a matter of preference how you want to work. If I have a Dpak transistor I do not want any information indicating that it is some other package. So whether that information field is controlling or not is negotiable. But I do not want anything in my schematic to be contradictory. It might be OK if that information field is empty or redundant, but I do not want it to be wrong.

A related “modus operandi” question (I think it is a matter of preference and the working situation) is; for example: Do I have one library symbol to cover all Dpack Nch MOSFETs or do I have a different symbol for each different one? One method requires more front end work while the other requires more back end work.

If my schematic does not produce the correct BOM, then when I edit the schematic I need to also make sure that I update the BOM. But if my schematic produces the correct BOM then the work is done once I correctly edit the schematic. So this is a good reason to put complete correct information into the schematic.

By the way I am looking at https://pypi.org/project/kifield/#files and trying to figure out what to do next. Now looking at https://packaging.python.org/tutorials/installing-packages/
Maybe I do not want to do this…

This is the exactly way I’m doing. It also the reason, I create the bom2sch, and bom2csv to ease the process, and less error-prone. Which I can just fix my BOM, and run bom2sch to update the data in eeschema. The bom2csv is generate a new csv file every time, so going from schematic to BOM you make lose addition column in the BOM. But this is my plain to have update the BOM instead of create new one in the future. So any addition into in BOM can be keep.

Hi, nhatkhai OK thanks that sounds good. I understand…Those script processes seem like they help your design flow. Perhaps I will want to figure out how to run those scripts once I get further into KiCad.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.