yaqwsx / KiKit

Automation tools for KiCAD
https://yaqwsx.github.io/KiKit
MIT License
1.54k stars 201 forks source link

'SwigPyObject' object has no attribute 'FootprintLoad' #571

Closed bradanlane closed 7 months ago

bradanlane commented 1 year ago

Prerequisites

KiKit version

1.3.0+25.g508cc19

KiCAD version

7.0.5

Operating system

Windows 11

Description

attempting to create a simple 1x1 panel. It's not clear if the issue is an oddity with the PCB or a bug in KiKit. The PCB passed DRC.

An error occurred: 'SwigPyObject' object has no attribute 'FootprintLoad'
No output files produced
Traceback (most recent call last):
  File "C:\Users\labmonitor\Documents\KiCad\7.0\3rdparty\Python39\site-packages\kikit\panelize_ui.py", line 217, in panelize
    doPanelization(input, output, preset, plugin)
  File "C:\Users\labmonitor\Documents\KiCad\7.0\3rdparty\Python39\site-packages\kikit\panelize_ui.py", line 278, in doPanelization
    ki.buildTooling(preset, panel)
  File "C:\Users\labmonitor\Documents\KiCad\7.0\3rdparty\Python39\site-packages\kikit\panelize_ui_impl.py", line 507, in buildTooling
    panel.addCornerTooling(4, hoffset, voffset, diameter, paste)
  File "C:\Users\labmonitor\Documents\KiCad\7.0\3rdparty\Python39\site-packages\kikit\panelize.py", line 1477, in addCornerTooling
    self.addNPTHole(pos, diameter, paste)
  File "C:\Users\labmonitor\Documents\KiCad\7.0\3rdparty\Python39\site-packages\kikit\panelize.py", line 1401, in addNPTHole
    footprint = pcbnew.FootprintLoad(KIKIT_LIB, "NPTH")
  File "C:\Program Files\KiCad\bin\Lib\site-packages\pcbnew.py", line 18579, in FootprintLoad
    return plug.FootprintLoad(libname,name,preserveUUID)
AttributeError: 'SwigPyObject' object has no attribute 'FootprintLoad'

Steps to Reproduce

{
    "layout": {
        "type": "grid",
        "rows": 1,
        "cols": 1,
        "hspace": "2mm",
        "vspace": "2mm"
    },
    "source": {
        "type": "auto",
        "tolerance": "2mm"
    },
    "tabs": {
        "type": "corner",
        "width": "4mm",
        "source": "none"
    },
    "cuts": {
        "type": "mousebites",
        "drill": "0.5mm",
        "spacing": "0.75mm",
        "offset": "-0.35mm",
        "prolong": "-0.4mm"
    },
    "framing": {
        "type": "tightframe",
        "hspace": "5mm",
        "vspace": "5mm",
        "slotwidth": "2.5mm",
        "width": "2.5mm"
    },
    "tooling": {
        "type": "4hole",
        "hoffset": "3.5mm",
        "voffset": "3.5mm",
        "size": "1.8mm"
    },
    "fiducials": {
        "type": "4fid",
        "paste": true,
        "hoffset": "13.5mm",
        "voffset": "3.5mm",
        "coppersize": "1mm",
        "opening": "1.5mm"
    },
    "post": {
        "type": "auto",
        "millradius": "1mm",
        "origin": "bl",
        "copperFill": false
    }
}
yaqwsx commented 1 year ago

Based on passing test suite and test performed in my setup, I suspect problem in your or Windows installation of KiCAD.

Could you run Python interpreter in the KiCAD Command prompt and put the following commands in there and share the output?

>>> import pcbnew
>>> pcbnew
>>> pcbnew.FootprintLoad

and then in a new interpreter:

>>> from pcbnewTransition import pcbnew
>>> pcbnew
>>> pcbnew.FootprintLoad
bradanlane commented 1 year ago

Not sure what the results are meant to tell me but here they are ...

Python 3.9.16 (main, May 18 2023, 07:48:16) [MSC v.1936 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcbnew
>>> pcbnew
<module 'pcbnew' from 'C:\\Program Files\\KiCad\\bin\\Lib\\site-packages\\pcbnew.py'>
>>> pcbnew.FootprintLoad
<function FootprintLoad at 0x0000024B2A13BAF0>

... and ...

Python 3.9.16 (main, May 18 2023, 07:48:16) [MSC v.1936 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pcbnewTransition import pcbnew
>>> pcbnew
<module 'pcbnewTransition.pcbnew' from 'C:\\Users\\labmonitor\\Documents\\KiCad\\7.0\\3rdparty\\Python39\\site-packages\\pcbnewTransition\\pcbnew.py'>
>>> pcbnew.FootprintLoad
<function FootprintLoad at 0x00000266E52DF040>

BTW: I use the same JSON on another PCB and it works fine.

yaqwsx commented 1 year ago

The output looks fine. In the case it works on other PCB, would you mind sharing the PCB that triggers the behavior? You can also do it non-publically via e-mail: email@honzamrazek.cz.

bradanlane commented 1 year ago

emailing

It has a number of customer footprints from a global library so opening it will likely have errors.

bradanlane commented 1 year ago

As a general comment, when I've had errors from KiKit, I can not determine if the error is related to the JSON settings, a specific component on the PCB, or something else.

If the error is related to a specific component (or trace, text, etc), would it be possible to include the description, ID, or other identifying attribute in the error message?

This would often reduce the diagnostics effort.

bradanlane commented 1 year ago

The issue is with the complex edge cut.

KiCAD recognizes the edge cut as being complete and renders the copper fill correctly. It will also generate valid GERBERs for the PCB.

However, swig is generating lots of memory leak messages and KiKit fails.

If I edit the edge cut to be very simple, the swig messages go away and KiKit has not problem generating the panel.

yaqwsx commented 1 year ago

I just tested the board you sent me, and it works fine on the latest master (that is kikit, version 1.3.0+39.g07c707d ). Could you test it? The error you observed should not have anything to do with it. Internal KiCAD function fails. The whole thing is strange.

bradanlane commented 1 year ago

I installed KiKit-1.3.0+39.g07c707d and I no longer get the swig messages but I still get the error.

The KiKit failure goes away if I change the edge cut.

update: If I reduce the PCB to nothing but the original edge cut (removing all traces, components, silk, etc) I get the error.

bradanlane commented 1 year ago

here is the "project" consisting of just the edge cut ... kikit_issue_571.zip

bradanlane commented 1 year ago

The error has returned when I use KiCad 7.0.7 and KiKit version 1.3.0+42.g63301c2.

this is using the complex edge cut

bradanlane commented 1 year ago

here is the latest project with just the end cut. It reproduces the error with kikit, version 1.3.0+42.g63301c2 kikit_issue_571_20230905.zip

bradanlane commented 1 year ago
Python 3.9.16 (main, May 18 2023, 07:48:16) [MSC v.1936 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcbnew
>>> pcbnew
<module 'pcbnew' from 'C:\\Program Files\\KiCad\\bin\\Lib\\site-packages\\pcbnew.py'>
>>> pcbnew.FootprintLoad
<function FootprintLoad at 0x000001DD53442670>

... and ...

Python 3.9.16 (main, May 18 2023, 07:48:16) [MSC v.1936 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pcbnewTransition import pcbnew
>>> pcbnew
<module 'pcbnewTransition.pcbnew' from 'C:\\Users\\labmonitor\\Documents\\KiCad\\7.0\\3rdparty\\Python39\\site-packages\\pcbnewTransition\\pcbnew.py'>
>>> pcbnew.FootprintLoad
<function FootprintLoad at 0x000001D8A53CCB80>
>>> quit()
bradanlane commented 1 year ago

If you can suggest of a workaround, I'm happy to try just about anything at this point.

yaqwsx commented 7 months ago

After 2 new releases of KiKit and the release of KiCAD 8 - is the problem solved or not? I struggled a lot with reproducing it and I still suspect a packaging issue in KiCAD rather than a bug in KiKit.

bradanlane commented 7 months ago

I have not been able to upgrade KiCAD since 7.0.7 because later 7.- released broke multiple things related to edge cuts.

I cannot move to 8.x until my current designs are done and shipped because I can't not afford the regression cycles.

If you want to close this, then go ahead. If this issue reappears after I move to 8.x I can either reopen it or create a new issue.

yaqwsx commented 7 months ago

As this is related to KiCAD packaging, I am closing this. It the problem reappears, please, let me know.