Differences between GERBERS generated via python and KiCad GUI

I have written some code to generate gerbers, but after a closer look, they are different (generated with the same settings) and I don’t know why.

Here is the python code:

def plot_gerbers(board, output_path):
    plot_controller = pcbnew.PLOT_CONTROLLER(board)
    plot_options = plot_controller.GetPlotOptions()

    plot_options.SetOutputDirectory(output_path)
    
    # Set General Options:
    plot_options.SetPlotFrameRef(PLOT_FRAME_REF)
    plot_options.SetPlotValue(PLOT_VALUES)
    plot_options.SetPlotReference(PLOT_REFERENCES)
    plot_options.SetPlotInvisibleText(PLOT_INVISIBLE_TEXT)
    plot_options.SetPlotViaOnMaskLayer(PLOT_VIA_ON_MASK_LAYER)
    plot_options.SetExcludeEdgeLayer(PLOT_EXCLUDE_EDGE_LAYER);
    plot_options.SetPlotPadsOnSilkLayer(PLOT_PADS_ON_SILK_LAYER);
    plot_options.SetUseAuxOrigin(PLOT_USE_AUX_ORIGIN)
    plot_options.SetMirror(PLOT_MIRROR)
    plot_options.SetNegative(PLOT_NEGATIVE)
    plot_options.SetDrillMarksType(PLOT_DRILL_MARKS_TYPE)
    plot_options.SetScale(PLOT_SCALE)
    plot_options.SetAutoScale(PLOT_AUTO_SCALE)
    plot_options.SetPlotMode(PLOT_MODE)
    plot_options.SetLineWidth(pcbnew.FromMM(PLOT_LINE_WIDTH))
    
    # Set Gerber Options
    plot_options.SetUseGerberAttributes(GERBER_USE_GERBER_ATTRIBUTES)
    plot_options.SetUseGerberProtelExtensions(GERBER_USE_GERBER_PROTEL_EXTENSIONS)
    plot_options.SetCreateGerberJobFile(GERBER_CREATE_GERBER_JOB_FILE)
    plot_options.SetSubtractMaskFromSilk(GERBER_SUBTRACT_MASK_FROM_SILK)
    plot_options.SetIncludeGerberNetlistInfo(GERBER_INCLUDE_GERBER_NETLIST_INFO)
    
    plot_plan = [
        ( "F.Cu", pcbnew.F_Cu, "Front Copper" ),
        ( "B.Cu", pcbnew.B_Cu, "Back Copper" ),
        ( "F.Paste", pcbnew.F_Paste, "Front Paste" ),
        ( "B.Paste", pcbnew.B_Paste, "Back Paste" ),
        ( "F.SilkS", pcbnew.F_SilkS, "Front SilkScreen" ),
        ( "B.SilkS", pcbnew.B_SilkS, "Back SilkScreen" ),
        ( "F.Mask", pcbnew.F_Mask, "Front Mask" ),
        ( "B.Mask", pcbnew.B_Mask, "Back Mask" ),
        ( "Edge.Cuts", pcbnew.Edge_Cuts, "Edges" ),
        ( "Eco1.User", pcbnew.Eco1_User, "Eco1 User" ),
        ( "Eco2.User", pcbnew.Eco2_User, "Eco1 User" ),
    ]
    
    for layer_info in plot_plan:
        plot_controller.SetLayer(layer_info[1])
        plot_controller.OpenPlotfile(layer_info[0], pcbnew.PLOT_FORMAT_GERBER, layer_info[2])
        plot_controller.PlotLayer()
    
    plot_controller.ClosePlot()

The Simple gerber generated by KiCad GUI
G04 #@! TF.GenerationSoftware,KiCad,Pcbnew,(5.0.1)-3*
G04 #@! TF.CreationDate,2018-12-06T22:00:52+01:00*
G04 #@! TF.ProjectId,Sample,53616D706C652E6B696361645F706362,rev?*
G04 #@! TF.SameCoordinates,Original*
G04 #@! TF.FileFunction,Paste,Bot*
G04 #@! TF.FilePolarity,Positive*
%FSLAX46Y46*%
G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)*
G04 Created by KiCad (PCBNEW (5.0.1)-3) date 06/12/2018 22:00:52*
%MOMM*%
%LPD*%
G01*
G04 APERTURE LIST*
%ADD10R,0.750000X0.800000*%
G04 APERTURE END LIST*
D10*
G04 #@! TO.C,C3*
X52700000Y-39600000D03*
X52700000Y-38100000D03*
G04 #@! TD*
M02*

And the one generated by the python
%TF.GenerationSoftware,KiCad,Pcbnew,(5.0.1)-3*%
%TF.CreationDate,2018-12-06T22:12:26+01:00*%
%TF.ProjectId,Sample,53616D706C652E6B696361645F706362,rev?%
%TF.SameCoordinates,Original
%
%TF.FileFunction,Paste,Bot*%
%TF.FilePolarity,Positive*%
%FSLAX46Y46*%
G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)*
G04 Created by KiCad (PCBNEW (5.0.1)-3) date 12/06/18 22:12:26*
%MOMM*%
%LPD*%
G01*
G04 APERTURE LIST*
%ADD10R,0.750000X0.800000*%
G04 APERTURE END LIST*
D10*
%TO.C,C3*%
X52700000Y-39600000D03*
X52700000Y-38100000D03*
%TD*%
M02*

They are almost the same but differences lie in the comments line:
in the KiCad GUI generated:
G04 #@! TF.FilePolarity,Positive* <- this is a comment preceded by G04
%FSLAX46Y46*% <- this is a parameter

in the python generated:
%TF.FilePolarity,Positive*% <- is this should be marked as comment? preceded by G04? or not?
%FSLAX46Y46*% <- this is a parameter

Maybe I have a incorrect settings in python script to generate gerbers properly?

Since TF or TO are not parameters I guess they must be comments.

ManualGerber.pdf (334.1 KB)

OK, I noticed that PLOT_CONTROLLER generates gerber X2 by default, so TF, TA, TO and TD are X2 commands. Thanks!

Is there any way to setup PLOT_CONTROLLER to generate a standard gerber? Maybe I should use GERBER_PLOTTER but I don’t know how can I link it with PLOT_CONTROLLER.

I have never used python scripts for Gerber generation.
Have you generated the X2 files from the plot menu? Just out of curiosity to see if your code is OK when generating Geber X2 files.

Yes, I have check it. Gerbers generated from KiCad GUI (with options Include extended X2 attributes and include advenced X2 features) are the same as genereated via my python script. Just out of curiosity I am wondering if it is possible to generate standard gerbers using PLOT_CONTROLLER.

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