devbisme / KiPart

Python package for generating multi-unit schematic symbols for KiCad from a CSV file.
MIT License
174 stars 46 forks source link

Empty rows are not handled correctly #59

Closed cnieves1 closed 2 years ago

cnieves1 commented 2 years ago

Hi, I see emtpy rows are not handled correctly.

If I run the command:

kipart -r generic -s row --box_line_width 20 test.csv -o test.lib --overwrite

on the attached file:

test.csv

Then it fails with:

Traceback (most recent call last):
  File "C:\Users\Carlos\AppData\Local\Programs\Python\Python38\Scripts\kipart-script.py", line 11, in <module>
    load_entry_point('kipart==1.0.0', 'console_scripts', 'kipart')()
  File "c:\users\carlos\appdata\local\programs\python\python38\lib\site-packages\kipart-1.0.0-py3.8.egg\kipart\kipart.py", line 1105, in main
    call_kipart(
  File "c:\users\carlos\appdata\local\programs\python\python38\lib\site-packages\kipart-1.0.0-py3.8.egg\kipart\kipart.py", line 883, in call_kipart
    return kipart(
  File "c:\users\carlos\appdata\local\programs\python\python38\lib\site-packages\kipart-1.0.0-py3.8.egg\kipart\kipart.py", line 837, in kipart
    parts_lib[part_num] = draw_symbol(
  File "c:\users\carlos\appdata\local\programs\python\python38\lib\site-packages\kipart-1.0.0-py3.8.egg\kipart\kipart.py", line 630, in draw_symbol
    balance_bboxes(bbox)
  File "c:\users\carlos\appdata\local\programs\python\python38\lib\site-packages\kipart-1.0.0-py3.8.egg\kipart\kipart.py", line 351, in balance_bboxes
    bal_bbox = find_bbox_bbox(bboxes["top"], bboxes["bottom"])
KeyError: 'top'
devbisme commented 2 years ago

The problem is you have a blank row in the middle of your part description at row 17 of your test file. Once I removed that, the file was processed correctly. As stated in the documentation: "4. A blank row ends the list of pins for the part." Once kipart saw the blank row, it assumed another part description was beginning and it misinterpreted the remaining rows of pin data because there was no part header or column headers.

Admittedly, there might be a need for a better error message here.