Gerber code generation¶
Overview¶
This section describes how to generate Gerber code with use of the
pygerber.builder.gerber
module.
All of the code building functionality is provided within
GerberX3Builder
class available in that module.
For reference of tools available in that module check out this reference page.
Creating pads¶
To generate Gerber code you need to create an instance of
GerberX3Builder
class, afterwards you can use
new_pad()
method to create a new pad shape which can be added to the image with
add_pad()
method.
example.py | |
---|---|
This is the rendered result of the example presented above:
Adding traces¶
You can also add traces to the image with
new_trace()
method and
add_arc_trace()
method.
example.py | |
---|---|
%FSLAX46Y46*%
%MOMM*%
%ADD10C,0.5*%
%ADD11C,0.1*%
D10*
X2000000Y1000000D03*
D11*
X0Y0D02*
X0Y1000000D01*
X2000000Y1000000D01*
M02*
This is the rendered result of the example presented above:
Using objects as locations¶
Commands creating graphical elements, like add_pad()
or add_trace()
return special
Draw
objects (PadDraw
or TraceDraw
respectively) which can be used as locations
for new_pad()
or new_trace()
methods. This way you don not have to retype
coordinates for draws which are connected to previous objects.
%FSLAX46Y46*%
%MOMM*%
%ADD10C,0.5*%
%ADD11C,0.1*%
D10*
X0Y0D03*
X2000000Y1000000D03*
D11*
X0Y0D02*
X0Y1000000D01*
X2000000Y1000000D01*
M02*
This is the rendered result of the example presented above:
Creating custom pads¶
You can create custom pads by using
custom()
method of object returned by new_pad()
method. Custom pads are built with use of
methods available on object returned by custom()
. Method calls can (and should) be
chained. When you are done adding elements to the pad, you should call create()
method
to finish the modification of custom pad and create concrete object representing it.
After calling create()
, you cannot and new elements to that custom pad.
Custom pad is used in the same way as any other pad, to add it to the image you should
use add_pad()
method.
%FSLAX46Y46*%
%MOMM*%
%AMM0*
1,1.0,0.2,1.0,1.0,0.0*
1,1.0,0.2,-1.0,1.0,0.0*
1,1.0,0.2,1.0,-1.0,0.0*
1,1.0,0.2,-1.0,-1.0,0.0*
20,1.0,0.15,1.0,1.0,-1.0,-1.0,0.0*
20,1.0,0.15,-1.0,1.0,1.0,-1.0,0.0*%
%ADD10M0*%
D10*
X0Y0D03*
X3000000Y0D03*
X6000000Y0D03*
M02*
This is the rendered result of the example presented above: