AttributeError: module 'pcbnew' has no attribute 'DRAWSEGMENT'

kicad 6.0.9 python 3.914

AttributeError: ‘BOARD’ object has no attribute ‘GetModules’

AttributeError: module ‘pcbnew’ has no attribute ‘TEXTE_PCB’
AttributeError: ‘PCB_TEXT’ object has no attribute ‘SetThickness’

How can i get the full change log for kicad python api?

How to port old code to the latest ?

Here is what I use for 5.1 and 6.0 (not the full list, just what is needed):

try:
    from pcbnew import (
        ActionPlugin, GetBoard, IU_PER_MM, IU_PER_MILS,
        PAD, PCB_TRACK, PCB_VIA, ZONE, ZONE_FILLER,
        wxPoint, wxPoint_Vector, wxSize,
        CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL,
        ZONE_SETTINGS,  # .SMOOTHING_NONE
        PAD_SHAPE_CIRCLE, PAD_SHAPE_RECT, PAD_SHAPE_OVAL,  # PAD_SHAPE_TRAPEZOID,
        PAD_SHAPE_ROUNDRECT, PAD_SHAPE_CHAMFERED_RECT, PAD_SHAPE_CUSTOM,
        PAD_ATTRIB_PTH, PAD_ATTRIB_SMD, PAD_ATTRIB_CONN, PAD_ATTRIB_NPTH,
        VIATYPE_THROUGH, ZONE_CONNECTION_FULL,
        ZONE_BORDER_DISPLAY_STYLE_NO_HATCH, ISLAND_REMOVAL_MODE_NEVER,
        ZONE_FILL_MODE_POLYGONS, ZONE_THICKNESS_MIN_VALUE_MIL,
        BOARD, FOOTPRINT, FP_EXCLUDE_FROM_POS_FILES, FP_EXCLUDE_FROM_BOM,
        PCB_SHAPE, SHAPE_T_CIRCLE, SHAPE_T_POLY, SHAPE_T_RECT,
        IO_MGR, LIB_ID, LSET, F_Fab, F_Cu, B_Cu,
    )
    FP_VIRTUAL = FP_EXCLUDE_FROM_POS_FILES | FP_EXCLUDE_FROM_BOM
    RECT_CHAMFER_ALL = 0xf
except ImportError:
    from pcbnew import (
        ActionPlugin, GetBoard, IU_PER_MM, IU_PER_MILS, 
        D_PAD as PAD, TRACK as PCB_TRACK, VIA as PCB_VIA, ZONE_CONTAINER as ZONE, ZONE_FILLER,
        wxPoint, wxPoint_Vector, wxSize,
        CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL,
        ZONE_SETTINGS,  # .SMOOTHING_NONE
        PAD_SHAPE_CIRCLE, PAD_SHAPE_RECT, PAD_SHAPE_OVAL,  # PAD_SHAPE_TRAPEZOID,
        PAD_SHAPE_ROUNDRECT, PAD_SHAPE_CUSTOM,
        PAD_ATTRIB_STANDARD as PAD_ATTRIB_PTH, PAD_ATTRIB_CONN, PAD_ATTRIB_SMD,
        PAD_ATTRIB_HOLE_NOT_PLATED as PAD_ATTRIB_NPTH,
        VIA_THROUGH as VIATYPE_THROUGH, PAD_ZONE_CONN_FULL as ZONE_CONNECTION_FULL,
        ZFM_POLYGONS as ZONE_FILL_MODE_POLYGONS, ZONE_THICKNESS_MIN_VALUE_MIL,
        BOARD, MODULE as FOOTPRINT, MOD_VIRTUAL as FP_VIRTUAL,
        DRAWSEGMENT as PCB_SHAPE, S_CIRCLE as SHAPE_T_CIRCLE, S_POLYGON as SHAPE_T_POLY, S_RECT as SHAPE_T_RECT,
        IO_MGR, LIB_ID, LSET, F_Fab, F_Cu, B_Cu,
    )
    ZONE_BORDER_DISPLAY_STYLE_NO_HATCH = ZONE.NO_HATCH
    ISLAND_REMOVAL_MODE_NEVER = PAD_SHAPE_CHAMFERED_RECT = RECT_CHAMFER_ALL = NotImplemented

(A)PI: KiCad Pcbnew Python Scripting: Class Hierarchy

1 Like

Current API is not a real api in conventional sense, it’s just kicad’s internals exposed via automatically generated python interface. So no change log other than git commit log.

File “C:\Program Files\KiCad\6.0\bin\Lib\site-packages\pcbnew.py”, line 13480, in GetShapeStr
return self.ShowShape(self.GetShape())
TypeError: ShowShape() takes 1 positional argument but 2 were given

    import pandas as pd
  File "C:\Program Files\KiCad\6.0\bin\Lib\site-packages\pandas\__init__.py", line 25, in <module>
    from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
  File "C:\Program Files\KiCad\6.0\bin\Lib\site-packages\pandas\_libs\__init__.py", line 13, in <module>
    from pandas._libs.interval import Interval
  File "pandas\_libs\interval.pyx", line 1, in init pandas._libs.interval
  File "C:\Program Files\KiCad\6.0\bin\Lib\site-packages\pandas\_libs\tslibs\__init__.py", line 37, in <module>
    from pandas._libs.tslibs.conversion import localize_pydatetime
  File "pandas\_libs\tslibs\conversion.pyx", line 77, in init pandas._libs.tslibs.conversion
  File "pandas\_libs\tslibs\parsing.pyx", line 1, in init pandas._libs.tslibs.parsing
  File "pandas\_libs\tslibs\offsets.pyx", line 1, in init pandas._libs.tslibs.offsets
  File "pandas\_libs\tslibs\timedeltas.pyx", line 77, in init pandas._libs.tslibs.timedeltas
  File "pandas\_libs\tslibs\fields.pyx", line 7, in init pandas._libs.tslibs.fields
  File "C:\Program Files\KiCad\6.0\bin\Lib\_strptime.py", line 268, in <module>
    _TimeRE_cache = TimeRE()
  File "C:\Program Files\KiCad\6.0\bin\Lib\_strptime.py", line 182, in __init__
    self.locale_time = LocaleTime()
  File "C:\Program Files\KiCad\6.0\bin\Lib\_strptime.py", line 69, in __init__
    self.lang = _getlang()
  File "C:\Program Files\KiCad\6.0\bin\Lib\_strptime.py", line 28, in _getlang
    return locale.getlocale(locale.LC_TIME)
  File "C:\Program Files\KiCad\6.0\bin\Lib\locale.py", line 593, in getlocale
    return _parse_localename(localename)
  File "C:\Program Files\KiCad\6.0\bin\Lib\locale.py", line 501, in _parse_localename
    raise ValueError('unknown locale: %s' % localename)
ValueError: unknown locale: zh-CN

It looks like some part to support Chinese is missing, and possibly some missing python (A)PI updates. Please report these issues using menu Help → :lady_beetle: Report Bug in KiCad.

1 Like

AttributeError: ‘BOARD’ object has no attribute ‘GetModules’

AttributeError: module ‘pcbnew’ has no attribute ‘MODULE’

    def add_pad(self, position, size, name='', pad_type='standard', shape='circle',
                drill=1.0, layers=None):
        """Create a pad on the module
        Args:
            position: pad position in mm
            size: pad size in mm, value if shape == 'circle', tuple otherwise
            name: pad name/number
            pad_type: One of 'standard', 'smd', 'conn', 'hole_not_plated'
            shape: One of 'circle', 'rect', 'oval', 'trapezoid'
            drill: drill size in mm, single value for round hole, or tuple for oblong hole.
            layers: None for default, or a list of layer definitions (for example: ['F.Cu', 'F.Mask'])
        """
        pad = Pad(pcbnew.D_PAD(self._module))

        pad.type = pad_type
        pad.shape = shape
        pad.size = size
        pad.name = name
        pad.position = position
        pad.layers = layers

        self._module.Add(pad._pad)
        return pad


D_PAD as PAD ## AttributeError: module ‘pcbnew’ has no attribute ‘D_PAD’

AttributeError: ‘BOARD’ object has no attribute ‘_module’

Take a look at the Replicate layout plugin in master and 5.99_test branch. This first one is a version that works in V5 while the second one is the version which works in V6. Looking at the diff you should get the idea what changed

When i set a new footprint in pcbnew,the footprint do not display instantly until I use mouse to click it. if i click other component. new footprint disappear again. what wrong with it?

	if not pcb:pcb = pcbnew.GetBoard()
	f='C:/test/x.kicad_mod'
	name='x.kicad_mod'
	sp  ='C:/test'
	plugin = pcbnew.IO_MGR.PluginFind(1)
	m=plugin.FootprintLoad(sp,name)
	if not m:
		return 0
	m.SetPosition(pcbnew.wxPoint(x,y))
	pcb.Add(m)