TypeError: 'SwigPyObject' object is not iterable

Traceback (most recent call last):
  File "C:\Users/Admin/Documents/KiCad/9.0/scripting\plugins\TextPostionSize\TextPosSize_dialog.py", line 120, in onProcessAction
    self.process_text(self.text_type)
  File "C:\Users/Admin/Documents/KiCad/9.0/scripting\plugins\TextPostionSize\TextPosSize_dialog.py", line 203, in process_text
    self.set_text(text_type,position=5)
  File "C:\Users/Admin/Documents/KiCad/9.0/scripting\plugins\TextPostionSize\TextPosSize_dialog.py", line 150, in set_text
    self.clear_fields(footprint)
  File "C:\Users/Admin/Documents/KiCad/9.0/scripting\plugins\TextPostionSize\TextPosSize_dialog.py", line 257, in clear_fields
    for index, field in fields:
TypeError: 'SwigPyObject' object is not iterable


    fields = footprint.GetFields()
    for index, field in fields:
        if index>5:
            field.SetVisible(False)

I want to hide the encapsulated redundant fields, and an error is reported here, is it impossible to get the field object?

GetFields() returns a simple array, if you want index and item then use enumerate() on it:

...
for index, field in enumerate(fields):
...
\TextPostionSize\TextPosSize_dialog.py", line 150, in set_text
    self.clear_fields(footprint)
  File "C:\Users/Admin/Documents/KiCad/9.0/scripting\plugins\TextPostionSize\TextPosSize_dialog.py", line 256, in clear_fields
    for index, field in enumerate(fields):
                        ^^^^^^^^^^^^^^^^^
TypeError: 'SwigPyObject' object is not iterable

Your problem is somewhere else, I just tested this on v9

for i, a in enumerate(fields):
    print(i, a.GetName())
    
0 Reference
1 Value
2 Footprint
3 Datasheet
4 Description

Check that footprint is actually FOOTPRINT instance


You are not actually calling GetFootprints, so your variable footprints is being assigned to be a “pointer” to the GetFootprints method rather than a list of footprints.

Maybe your install is borked if you’ve been overwriting versions, try reinstalling kicad.

I uninstalled and then installed the latest version of the nightly version today and the error still appeared. I suspect it’s the nightly version code that is broken



@craftyjon