~barbeque


#4 KeyError: 'Reference' on mounting holes 9 months ago

Ticket created by ~barbeque on ~martijnbraam/turbocase

Hi, I love the project. Thank you for making it!

I am using it on a KiCad PCB where I've manually added the mounting holes using the "add footprint" command in the PCB editor ("A" shortcut.) The footprint is MountingHole_3.2mm_M3_DIN965.

When I run turbocase it crashes claiming that the hole has no property Reference, which could be true (the KiCad editor says it has a field named "Reference designator").

% turbocase project.kicad_pcb case.scad
Traceback (most recent call last):
  File ".../env/bin/turbocase", line 8, in <module>
    sys.exit(main())
  File ".../env/lib/python3.9/site-packages/turbocase/__main__.py", line 64, in main
    case = load_pcb(args.pcb, args.layer, args.lid_layer)
  File ".../env/lib/python3.9/site-packages/turbocase/kicad.py", line 390, in load_pcb
    ref = hole.property['Reference']
KeyError: 'Reference'

I ended up modifying the code to handle this case in a sort of juvenile way:

unknown_holes = 0 
    
    for hole in mountingholes:
        center = hole['at'][:]
        # new code begins here
        if 'Reference' not in hole.property:
            hole.property['Reference'] = f"HOLE{unknown_holes}"
            unknown_holes += 1
        # new code ends here    
        ref = hole.property['Reference']

After making it generate references for each of the unknown refs, it produces a nice case.

My KiCad version is 7.0.9 if that matters, and I can send you the kicad_pcb file via email or a GitHub link if you want to look at it more closely. Thank you again for such a great project!