devbisme / KiField

Edit/insert/delete part fields in KiCad schematics or libraries using a spreadsheet.
MIT License
70 stars 27 forks source link

Setting visibility fails due to missing "effects" property in Reference field #73

Closed iank closed 2 years ago

iank commented 2 years ago

Describe the bug Adding new fields and setting visibility fails, maybe due to a change in Kicad 6 schematic files

To Reproduce Steps to reproduce the behavior:

  1. Extract fields from kicad_sch to CSV
  2. Add a new field with [I] or [V] prefix
  3. Extract fields from CSV to kicad_sch
kifield -x toast.csv -i toast.kicad_sch -w -r
Traceback (most recent call last):
  File "C:\Users\ian\AppData\Local\Programs\Python\Python310\Scripts\kifield-script.py", line 33, in <module>
    sys.exit(load_entry_point('kifield==0.2.0', 'console_scripts', 'kifield')())
  File "C:\Users\ian\AppData\Local\Programs\Python\Python310\lib\site-packages\kifield-0.2.0-py3.10.egg\kifield\__main__.py", line 149, in main
    kifield(
  File "C:\Users\ian\AppData\Local\Programs\Python\Python310\lib\site-packages\kifield-0.2.0-py3.10.egg\kifield\kifield.py", line 1552, in kifield
    insert_part_fields(
  File "C:\Users\ian\AppData\Local\Programs\Python\Python310\lib\site-packages\kifield-0.2.0-py3.10.egg\kifield\kifield.py", line 1516, in insert_part_fields
    insertion_function(
  File "C:\Users\ian\AppData\Local\Programs\Python\Python310\lib\site-packages\kifield-0.2.0-py3.10.egg\kifield\kifield.py", line 1196, in insert_part_fields_into_sch_V6
    component.set_field_visibility(f["name"], total_vis)
  File "C:\Users\ian\AppData\Local\Programs\Python\Python310\lib\site-packages\kifield-0.2.0-py3.10.egg\kifield\sch.py", line 460, in set_field_visibility
    effects = find_by_key("effects", field["prop"])[0]
IndexError: list index out of range

Expected behavior Fields should be added w/ show/hide setting set appropriately. Instead, kifield crashes. To add a new field I think kifield is deep-copying the reference designator field, and then if it needs to set visibility it finds the "effects" property and sets it. It looks like Kicad has since changed, and the Reference field doesn't include the "effects" property unless it's been overridden from defaults? Changing the template field from Reference to Datasheet works in my case since Datasheet appears to include the "effects" property, but probably a better solution is to just generate it.

Desktop (please complete the following information):