Creating components
Component creation
A new component is created by using the create component command and specifying the pins parameter.
my_component = create component:
pins: 2
at my_component
The code above creates a component object with 2 pins. The pins are automatically generated with a pin ID of 1 and 2 respectively.
Pin names can also be defined in the symbol object:
my_component = create component:
pins:
1: "anode"
2: "cathode"
at my_component
Properties during component creation
The following properties may be declared during component creation:
| Name | Description |
|---|---|
pins | If a single number is specified, the number of pins will be automatically created. Otherwise, pins with the given ID and names will be generated |
type | Type of component, this may be used to determine the refdes group of the component. Supported values: net, label, res, cap, ind, diode, conn |
display | Specify the graphic to display as the symbol of the component. If unspecified, a default rectangular symbol is generated. |
arrange | If display is not specified, then the arrangement of pins must be specified. |
copy | If this is set to true, whenever this component is referenced, a copy of the component will be created and used instead. |
refdes_prefix | Custom reference designator prefix for the component (e.g., "U", "IC", "X"). Overrides the default prefix determined by the component type. |
params | A map that specifies parameters of the component. This may be changed after component creation. Please see this page for more information. |
Component graphical symbol
By default, the graphical symbol for the component is generated automatically. Pins are arranged in a zig-zag arrangement.
Default graphical symbol
my_component = create component:
pins: 10
at my_component # need at least an `at` command to display the component in the schematic.
Specifying pin positions
The position of each component pin can be specified using the arrange parameter. Specify which pin IDs are to be placed on the left and right sides of the component.
my_component = create component:
pins: 10
arrange:
left: 1, 2, 3, 4
right: 5, 6, 7, 8, 9, 10
at my_component
Blank pin positions
To add spaces between pins, use the blank placeholder [<number] to specify a blank pin position.
my_component = create component:
pins: 10
arrange:
left: [1], 1, [2], 2, 3
right: 4, 5, 6, 7, 8, 9, 10
at my_component
Component pin types
The pin type of each component can be specified to provide more information about the pin. The following pin types are supported:
| Pin Type | String Literal | Description |
|---|---|---|
Passive | "passive" | Default type; no drive capability, connects freely (resistors, capacitors) |
Any | "any" | Matches any other pin type; no connectivity restrictions |
Input | "input" | Signal input; consumes a driven signal |
Output | "output" | Signal output; drives a signal onto the net |
IO | "io" | Bidirectional signal pin (input or output) |
HiZ | "hiz" | High-impedance; can be tristated, does not actively drive |
OpenCollector | "open_collector" | Open-collector/open-drain; pulls low, needs external pull-up |
OpenEmitter | "open_emitter" | Open-emitter; pulls high, needs external pull-down |
Power | "power" | Power net declarations (i.e. supply symbols, VCC, VDD) |
PowerReference | "power_reference" | Reference potential net (e.g. GND symbol, component GND pins) |
PowerInput | "power_input" | Consumes from a voltage rail (component VCC/VDD pins) |
PowerOutput | "power_output" | Sources/drives a voltage rail (regulator output) |
NoConnect | "no_connect" | Explicitly unconnected; suppresses ERC unconnected-pin warnings |
Example:
my_component = create component:
pins:
1: "IN", "input"
2: "OUT", "output"
3: "VCC", "power_input"
4: "GND", "power_reference"
at my_component
The above component created has two power pins, one for pin 3 (VCC) and pin 4 (GND). Pin 1 is a signal input pin and pin 2 is a signal output pin.
Drawing custom component graphics
Custom component graphics is drawn using the create graphic command. Specfic drawing commands can be used to draw the component body and also define the placement of component pins.
width = 100
height = 100
my_component = create component:
pins: 2
display: create graphic(params):
triangle: -width/2, 0, width/2, 0, height
vline: width/2, -height/2, height
hpin: 1, -width/2-100, 0, 100 # anode
hpin: 2, width/2 + 100, 0, -100 # cathode
label: params.refdes, 0, -80, fontSize=50, anchor="center", vanchor="bottom"
at my_component
The syntax for drawing commands are as follows: <command>: <arg1>, <arg2>, ...
pin command
pin: <pin ID: number>, <pin start x: number>, <pin start y: number>, <pin end x: number>, <pin end y: number>
The pin consists of the pin start point and the pin end point. The pin start point is where wires and other components connect to.
If the pin type is not defined, the pin will have a pin type of "passive".
Example:
my_component = create component:
pins: 2
display: create graphic:
rect: -100, -50, 200, 100
pin: 1, -200, 0, -100, 0
pin: 2, 200, 0, 100, 0
path: ("M", 125, -50, "L", 200, -50,
"M", 150, -75, "L", 125, -50, "L", 150, -25)
path: ("M", -125, -50, "L", -200, -50,
"M", -150, -75, "L", -125, -50, "L", -150, -25)
at my_component pin 1
wire left 100
at my_component pin 2
wire right 100
In the example above, the arrows indicate the direction of the pins. When building circuits, wires and other components are always connected at the start of the pin. In the example above, the wires are connected at side of the pin without the arrow-head.
pin command with pin name
pin: <pin ID: number>, <pin name: string>, <pin type: string>, <pin start x: number>, <pin start y: number>, <pin end x: number>, <pin end y: number>
This command displays the pin name beside the pin and the pin name is placed at the end point of the pin.
Example:
my_component = create component:
pins: 2
display: create graphic:
rect: -100, -50, 200, 100
pin: 1, "A", "passive", -200, 0, -100, 0
pin: 2, "B", "passive", 200, 0, 100, 0
path: "M", 125, -50, "L", 200, -50, \
"M", 150, -75, "L", 125, -50, "L", 150, -25
path: "M", -125, -50, "L", -200, -50, \
"M", -150, -75, "L", -125, -50, "L", -150, -25
at my_component pin 1
wire left 100
at my_component pin 2
wire right 200
In the above example, the pin name is displayed beside the pins and the pins are defined with a type of "passive".
Additional properties:
- Set
display_id=falseto skip drawing of pinId beside the pin - Set
display_name=falseto skip drawing of name beside the pin
hpin command
This command is a simplification of the pin command and is used to draw horizontal pins.
hpin: <pin id>, <pin start x: number>, <pin start y: number>, <pin x length>
With pin name and type:
hpin: <pin id>, <pin name: string>, <pin type: string>, <pin start x: number>, <pin start y: number>, <pin x length>
See this table for the possible pin types.
vpin command
This command is a simplification of the pin command and is used to draw vertical pins.
vpin: <pin id>, <pin start x: number>, <pin start y: number>, <pin y length>`
With pin name and type:
vpin: <pin id>, <pin name: string>, <pin type: string>, <pin start x: number>, <pin start y: number>, <pin y length>`
See this table for the possible pin types.
rect command
Draws a rectangle by specifying the top-left coordinate of the rectangle, followed by the width and height.
rect: <x: number>, <y: number>, <width: number>, <height: number>
crect command
Draws a rectangle by specifying the center of the rectangle, followed by the width and height.
crect: <center x: number>, <center y: number>, <width: number>, <height: number>
label command
label: <text: string>, <x: number>, <y: number>, <...named parameters>
Currently, only the following named parameters are accepted:
- fontSize: number
- anchor: One of "left", "center", "right",
- vanchor: One of "top", "center", "bottom"
hline command
Draws a horizontal line of a given length starting from the point.
hline: <x: number>, <y: number>, <length: number>
vline command
Draws a vertical line of a given length starting from the specified point.
vline: <x: number>, <y: number>, <length: number>
arc command
Draws a section of a circle at a given location and radius. The section is drawn in a clockwise direction from the starting angle to the ending angle.
arc: <center x>, <center y>, <radius>, <starting angle>, <ending angle>
path command
path: <... array of drawing instructions>
The path command is similar to path in the SVG spec.
Example:
path: "M", 0, 0, "L", 10, 10
This path command moves the drawing cursor to (0, 0) and draws a line until (10, 10)
path: "M", 100, 100, "L", 200, 200, "L", 200, 100
This path commands starts at (100, 100), draws a line until (200, 200) and a further line until (200, 100)
At the moment, only the "M" and "L" instructions are supported.
fill command
Sets the current fill color used for drawing closed shapes (circles, rectangles, paths, etc.)
text_color command
Sets the current text color used for drawing text
line_color command
Sets the current line color used for drawing line
line_width command
Sets the current line width used for drawing lines