Including title block in plot with python

I try to write a script which generates a PDF, SVG or similar from the PCB which includes the title block. As far as i understand, i can set this with SetPlotFrameRef(True). But then i get the error /build/kicad-UH8AyZ/kicad-5.1.5+dfsg1/pcbnew/pcbnew.cpp(218): assert "process" failed in Pgm(). in OpenPlotfile(...) and a segmentation fault. It works when i change it to SetPlotFrameRef(False), but then i don’t have a title block.
Is SetPlotFrameRef(True) the correct way to include the title block in a plot?
Is there a way to avoid the segmentation fault?
How does pcbnew know which kicad_wks file to use? I know that this is not stored in the kicad_pcb file. Do i need to set it somehow first?

A simple version of my script:

#!/usr/bin/python3
import pcbnew
import sys

layers=[[ "F.Cu", "cu_top"  ]]
 
def debug(n):
  sys.stderr.write("DEBUG "+str(n)+"\n")
 
def plot(input,outPath,format=pcbnew.PLOT_FORMAT_PDF):
  controller=pcbnew.PLOT_CONTROLLER(input)
  options=controller.GetPlotOptions()
  options.SetFormat(format)
  options.SetPlotFrameRef(True)       #It works without this
  options.SetOutputDirectory(outPath) 
  for layer in layers:
    controller.SetLayer(input.GetLayerID(layer[0]))
    debug(0)
    controller.OpenPlotfile(layer[1],format,layer[1])
    debug(1)
    controller.PlotLayer()

input=pcbnew.LoadBoard("<path/to/pcb/file.kicad_pcb>")
#did try to add title block ,didn't work
#input.SetTitleBlock(pcbnew.TITLE_BLOCK())
plot(input,".")

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