Suppress assertions from python code

Hi,

I get this alert when I run a python script which exports gerbers from a KiCad 7 file.
image

It pops up when the masks are being exported. The line that causes it is 43 at KiCad PCB EDA Suite: board_item.cpp Source File

When I press cancel the alert closes and the code runs successfully.
I tried to run python with -O to suppress asserts but that did not work.

I am wondering if there is a way to suppress this alert so it does not pop up at all?

Its worth to mention that this does not happen with all KiCad files. Just for some of them. Unfortunately, I cannot share said files.

I guess you are building KiCad from source? If so, use a Release build, not a Debug build.

I dont think this is a debug release. I downloaded it from here:
https://downloads.kicad.org/kicad/windows/explore/stable/download/kicad-7.0.0-x86_64.exe

Does it still happen in 8.0.4? Or 7.0.11?

Why are you using the oldest and buggiest possible version of 7.0? Lol

Quite a lot of people do not realize how quickly KiCad is evolving. With a lot of programs that are 20 or more years on the market the codebase has pretty much stabilized and lacks innovation. As a result people just stopped caring whether their software lags a few mayor versions behind.

Another reason why people became skeptical about updating is the move to the “cloud” and the rental model of monthly or yearly payments, while they have a perpetual license for an older version. This makes (at least some) people think about whether upgrading to the newest version with only a few new features is actually an advantage for them, and thus also strengthens the idea of just keeping on working with the old version.

None of these reasons are of course valid for KiCad which both evolves rapidly and comes with free perpetual upgrades. But when you get into the above mindset, it’s easy to forget to upgrade, unless you’re on Linux, in which the OS handles the upgrades of all properly installed programs during normal system maintenance.

Tried now both 7.0.11 and 8.0.4
image

They both produce the alert message.

@marekr I inherited the project from another developer and it is a complex system. KiCad and this gerber export script is a small part of it. I know nothing about cam. Changing any version could have an effect on scripts that would be time consuming to debug. On top of this @paulvdh is right.

OK. You can report a bug with this if you can share the Python script and the board in question. For now it is impossible to say with the information we have so far whether or not this is a bug in the Python script or a bug in KiCad.

So is there no generic way to suppress the alerts?

I can share the script but not the board.

The script is:

from pcbnew import *
filename="c:\\development\\kicad\\test.kicad_pcb"
board = LoadBoard(filename)

pctl = PLOT_CONTROLLER(board)
popt = pctl.GetPlotOptions()

#DRILL
drlwriter = EXCELLON_WRITER( board )
drlwriter.SetMapFileFormat( PLOT_FORMAT_PDF )
mirror = False
minimalHeader = False
offset = wxPoint(0,0)
mergeNPTH = True

metricFmt = True
drlwriter.SetFormat( metricFmt )
genDrl = True
genMap = False
outputPath = "c:\\development\\kicad"
drlwriter.CreateDrillandMapFilesSet( outputPath, genDrl, genMap )

#GERBER
popt.SetPlotFrameRef(False)
popt.SetAutoScale(False)
popt.SetScale(1)
popt.SetMirror(False)
popt.SetUseGerberAttributes(True)
popt.SetScale(1)
popt.SetUseAuxOrigin(False)

plot_plan = [
	( "CuTop", F_Cu, "Top layer" ),
	( "CuBottom", B_Cu, "Bottom layer" ),
	( "MaskTop", F_Mask, "Mask top" ),
	( "MaskBottom", B_Mask, "Mask bottom" ),
	( "SilkTop", F_SilkS, "Silk top" ),
	( "SilkBottom", B_SilkS, "Silk top" ),
	( "EdgeCuts", Edge_Cuts, "Edges" ),
	( "PasteTop", F_Paste, "Paste top" ),
	( "PasteBottom", B_Paste, "Paste Bottom" ),
]

for layer_info in plot_plan:
    pctl.SetLayer(layer_info[1])
    pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_GERBER, layer_info[2])
    pctl.PlotLayer()

lyrcnt = board.GetCopperLayerCount()

for innerlyr in range ( 1, lyrcnt-1 ):
    pctl.SetLayer(innerlyr)
    lyrname = 'CuIn%s' % innerlyr
    pctl.OpenPlotfile(lyrname, PLOT_FORMAT_GERBER, "inner")
    pctl.PlotLayer()

pctl.ClosePlot()

Python scripting in KiCad is based on SWIG, and it is not a very stable interface. It is common that scripts break between mayor KiCad versions, but updating to the latest bug fix release should be quite safe. For KiCad, bug fix releases are made approximately once a month, and each time the 3rd number of the KiCad version number is incremented. Each month some 70 to 100 bugs get fixed, so lagging that far behind is not good. The first mayor release of KiCad also tends to have quite a lot of small bugs. Because of this many people (especially companies) wait a few bug fix releases before upgrading to the next mayor release. It is also quite common to only upgrade the mayor version once the last bug fix release of a series has been released.

For now, KiCad seems to settle on a yearly release schedule for the mayor version upgrade in February, just a short while before FOSDEM

Maybe it is an option for you to use kicad-cli It is a command line program that can be used in scripts outside of KiCad. It has quite a lot of built in help, but no man page. You get to the build in help, when the command line is not complete, and then it shows a page with keywords for the last valid command line option. I.e, kicad-cli pcb export gerber shows the options for exporting gerber files.

paul@cezanne:~$ kicad-cli pcb export gerber
input: 1 argument(s) expected. 0 provided.
Usage: gerber [--help] [--output OUTPUT_FILE] [--layers LAYER_LIST] [--drawing-sheet SHEET_PATH] [--define-var KEY=VALUE] [--exclude-refdes] [--exclude-value] [--include-border-title] [--no-x2] [--no-netlist] [--subtract-soldermask] [--disable-aperture-macros] [--use-drill-file-origin] [--precision PRECISION] [--no-protel-ext] INPUT_FILE

Plot given layers to a single Gerber file

Positional arguments:
  INPUT_FILE                     Input file 

Optional arguments:
  -h, --help                     Shows help message and exits 
  -o, --output                   Output file [nargs=0..1] [default: ""]
  -l, --layers                   Comma separated list of untranslated layer names to include such as F.Cu,B.Cu [nargs=0..1] [default: ""]
  --drawing-sheet                Path to drawing sheet, this overrides any existing project defined sheet when used [nargs=0..1] [default: ""]
  -D, --define-var               Overrides or adds project variables, can be used multiple times to declare multiple variables.
                                 Use in the format of '--define-var key=value' or '-D key=value' [nargs=0..1] [default: {}]
  --erd, --exclude-refdes        Exclude the reference designator text 
  --ev, --exclude-value          Exclude the value text 
  --ibt, --include-border-title  Include the border and title block 
  --no-x2                        Do not use the extended X2 format 
  --no-netlist                   Do not generate netlist attributes 
  --subtract-soldermask          Subtract soldermask from silkscreen 
  --disable-aperture-macros      Disable aperture macros 
  --use-drill-file-origin        Use drill/place file origin 
  --precision                    Precision of Gerber coordinates, valid options: 5 or 6 [nargs=0..1] [default: 6]
  --no-protel-ext                Use KiCad Gerber file extension

That looks promising. Ill try this in the coming days.
Thanks and also for above explanation of how KiCad applies semver.

Script looks fine, isn’t doing anything risky. There is probably some issue with the board in question that KiCad isn’t handling well.

I do think that despite the script being fine, anyone using a script to generate outputs like this should switch over to the CLI as Paul recommended.

I did try the CLI now. It is not suitable for me. It is slower to export each layer to its own file and the file sizes are different so I assume the exported files differ.

If i plot the masks from KiCad directly it runs fine without the alert

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