Pcbnew python API, plot fabrication output in pdf

Hello,

I’m writing a plug-in based on the pcbnew python API to generate automatically all internal documents needed for PCB ordering and quality management, but I’m struggling with the PDF page format.

When I execute the following code, the plot on the page is not centered and the scale is too big (part of the drawing sheet is missing); even if the SetAutoScale is set to True. Moreover, the layer is printed in white, so it is not visible (white on white). I noticed that because I see some objects when I select everything on the pdf. Note that when I change the option SetBlackAndWhite to True, then the layer is well printed into black.

Do you know how to scale and offset the plot on the page?
About the color issue is there some setting I’m missing?

I tried to do the same with the Command Line Interface, but then the layer name is not printed on the drawing sheet.

Any link to an example or documentation is of course welcome.
Thanks for your help.
Best regards

import pcbnew

pcb = pcbnew.GetBoard()
plot_controller = pcbnew.PLOT_CONTROLLER(pcb)
plot_options = plot_controller.GetPlotOptions()

plot_options.SetPlotFrameRef(True)
plot_options.SetAutoScale(True)
plot_options.SetUseAuxOrigin(False)
plot_options.SetA4Output(True)
plot_options.SetBlackAndWhite(False)

plot_controller.SetLayer(pcbnew.F_Cu)
plot_controller.OpenPlotfile(pcbnew.F_Cu, pcbnew.PLOT_FORMAT_PDF, "Front copper")
seq = pcbnew.LSEQ()
seq.push_back(pcbnew.F_Cu)
seq.push_back(pcbnew.Edge_Cuts)
seq.push_back(pcbnew.Cmts_User)
seq.push_back(pcbnew.Dwgs_User)
plot_controller.PlotLayers(seq)
plot_controller.ClosePlot()

Although I’ve written a handful of Plugin’s for my own needs, I know Nothing about making one for Plotting so, this may not help but, will mention it…

re: v6 (and may apply to v7) To successfully Plot either SVG or PDF, the only way it works for me is to Set the Units to INCHes and Origin to ABSOLUTE. With those set, I can plot correctly, and the Negative Checkbox works with these set…

Thus, I suggest testing the Plotting of PDF/SVG from the PCB first, then if successful, ensure your Code sets plot/units/origin…etc

Test Example below shows the PCB and the Plotted Front layer

Screenshot of Plottted PDF section showing the graphic, Not the full page

Plotted SVG full page
PDF_SVG_Plot_Test1-F_Cu

Dear BlackCoffee,
Anyway thanks trying to help me, I appreciate it. Unfortunately, when I plot “manually” from the PCB, with the same checkbox settings, everything goes well : layer color is there, drawing is perfectly centered and scaled. CLI behaves also well, the only missing information here is the layer name. I only have those color and position issues with the python API.
I hope it’s only a my misunderstanding or a setting issue, but I’m afraid that the API is still under development and some bugs still exist …
Thanks for your help
Best regards

1 Like

If you are prepared to dig a bit you may find the answers you are looking for in this project

I don’t know if it uses native plotter class or renders objects on it’s own but it may at least give you a workaround.

Dear qu1ck,

I downloaded the Albin Board2Pdf plugin and it works fine. Not color issue, not off-centering. Thanks for sharing this link. I can now dig into this code and find the right pcbnew settings.
It’s great to have such example for my project, thanks again

Best regards

1 Like

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