The vias generated by the script are only visible when I click on them

Description

Hello,
I created a simple script that creates vias on the coordinates of the circles located in the User.9 layer. The problem is that after running the script, these vias cannot be seen. However, I can select them with the mouse.

However, if I copy and paste the generated via, it is already OK. Also, if I save the board and reopen it, everything is fine.

Am I missing a step in the script or is it a KiCad error?
Thanks a lot for the advice.

My script

import pcbnew


class Plugin(object):

    def __init__(self) -> None:
        super().__init__()
        self.board = pcbnew.GetBoard()
        self.circles = []
        self.get_circles()
        self.add_vias()
        pcbnew.Refresh()

    def get_circles(self):
        for item in self.board.GetDrawings():
            if type(item) is not pcbnew.PCB_SHAPE:
                continue
            if item.GetShapeStr() != 'Circle':
                continue
            if item.GetLayerName() != 'User.9':
                continue
            self.circles.append(item)

    def add_vias(self):

        netcode = self.board.GetNetcodeFromNetname('GND')

        for circle in self.circles:
            position = circle.GetPosition()
            diameter = 2 * circle.GetRadius()
            print(diameter, position)
            via = pcbnew.PCB_VIA(self.board)
            via.SetDrill(diameter)
            via.SetWidth(int(diameter * 1.3))
            via.SetPosition(position)
            via.SetViaType(pcbnew.VIATYPE_THROUGH)
            via.SetNetCode(netcode)
            via.SetIsFree(False)
            via.SetLayerPair(pcbnew.F_Cu, pcbnew.B_Cu)
            self.board.Add(via)


if __name__ == '__main__':
    plug = Plugin()

I run the script from the scripting console in the PCB Editor with this command:

exec(open('path_to_my_script.py').read())

KiCad Version

Application: KiCad PCB Editor

Version: 5.99.0-unknown-a90656900a~131~ubuntu20.04.1, release build

Libraries:
	wxWidgets 3.0.4
	libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3

Platform: Linux 5.4.0-80-generic x86_64, 64 bit, Little endian, wxGTK, cinnamon, x11

Build Info:
	Date: Aug  9 2021 04:14:03
	wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24
	Boost: 1.71.0
	OCC: 7.3.0
	Curl: 7.68.0
	ngspice: 31
	Compiler: GCC 9.3.0 with C++ ABI 1013

Build settings:
	KICAD_USE_OCC=ON
	KICAD_SPICE=ON

This is a known issue: https://gitlab.com/kicad/code/kicad/-/issues/7065

Thank you for answer.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.