Constrain an automatic route
An automatic connection is a useful starting point. When a signal needs to pass through a particular corridor, add only the geometry you need to control. This lesson compares an unconstrained route, a fixed segment and an automatic waypoint.
Make a connection the router can solve
import PCB, { nets, route } from '@pcbjs/core' import { PinHeader, rect } from '@pcbjs/lib' const { SIG } = nets({ SIG: { class: 'signal' } }) const J1 = PinHeader(1)().connect({ 1: SIG }) const J2 = PinHeader(1)().connect({ 1: SIG }) export default ( <PCB name="RoutePractice" classes={{ signal: { width: 0.3, clearance: 0.25 } }}> <path layer="Edge.Cuts" d={rect(32, 22)} /> <J1 at="5 5" /> <J2 at="26 16" /> {route(J1[1], J2[1]).layers(['F.Cu']).vias(false)} </PCB> )
The route takes its width and clearance from the signal class. The builder limits its automatic legs to front copper and forbids vias. Inspect the resulting path in dev, then move J2 and watch the route respond.
Preserve one decision
Replace the route expression with route(J1[1], J2[1]).width(0.3).V(10). The first segment now runs to absolute y = 10 in the current frame. Because the chain stops short of J2, an automatic leg finishes the connection.
Next try route(J1[1], J2[1]).width(0.3).X('15 12').X(). The router solves a path to the waypoint, then a path to J2. The waypoint fixes where the route must pass; it does not force a straight line through obstacles.
By comparison, .Z() finishes with a straight manual segment to the end. It draws the geometry you requested even when that geometry creates a finding. Use it when you intend to own that segment's path.
Blinky mixes fixed geometry and automatic completion. Follow a routing range to see which copper it controls:
// Blinky: three LED channels switched by one transistor on a 30 x 20 mm two-layer board, in three files: // blinky.sch.tsx has the nets, parts and schematic picture, blinky.sourcing.ts the part numbers, and this file the layout. // Frame: millimetres, origin at the top-left corner of the outline, x right, y down (SVG). // C1 sits on the back because CH2's led track runs over its spot on the front, and its chip footprint prints no ref. // VCC runs from J1.2 to a bus at x = 9 where each channel row starts, then to a via and C1 on the back. import PCB, { route, pour, via } from '@pcbjs/core' import { Brand, rect, roundedRect } from '@pcbjs/lib' import * as sch from './blinky.sch' import './blinky.sourcing' import { layout as LedChannelRow } from './lib/led-channel' const W = 30, H = 20 export default ( <PCB name="Blinky" rev="0.1.0" schematic={sch} rules={{ clearance: 0.2, minTrackWidth: 0.2, requireSourcing: true }} autoroute={{ bend: '45', viaCost: 4 }}> <path layer="Edge.Cuts" d={roundedRect(W, H, 2)} /> {/* J1, Q1 and C1 by hand, each channel by its circuit's row layout */} <J1 at="3 8" /> <Q1 at="26 10" /> <LedChannelRow g={CH1} at="16 5" label="LED1" /> <LedChannelRow g={CH2} at="16 10" label="LED2" /> <LedChannelRow g={CH3} at="16 15" label="LED3" /> <C1 at="15 10" side="B" /> <text layer="B.SilkS" at="15 8.3" size={0.8}> C1 </text> {/* tracks as path strings, a via, and a chain whose last hop .X() leaves to the autorouter */} {route('3 10').net(VCC).width(0.3).H(9)} {route('9 5').net(VCC).width(0.3).V(15)} {route('9 11.6').net(VCC).width(0.3).H(15.8)} {via(VCC, '15.8 11.6')} {route('15.8 11.6').net(VCC).layer('B.Cu').width(0.3).V(10)} {route('22.2 5').net(SW).width(0.3).V(16.5).H(27).V(10)} {route(J1[3], Q1[1]).width(0.25).V(14).L(5, 16).via('B.Cu').X('24 16').V(7.5).via('F.Cu')} {/* GND: a pour over the back, Q1.2 autorouted into it */} {route(Q1[2], '25 12.5 B.Cu').width(0.3)} {pour(GND, 'B.Cu', rect(W, H))} <text layer="F.SilkS" at="3 4.3" size={0.8}> GND </text> <text layer="F.SilkS" at="15 18.5" size={1}> Blinky · pcbjs </text> <Brand at="15 4" height={5} layer="B.SilkS" /> </PCB> )
Read a failed route as feedback
Run npx pcbjs check. If a restrictive layer choice or narrow corridor prevents routing, inspect the reported leg and nearby objects before loosening constraints. Try a more useful waypoint or move a part; increasing width or clearance can reduce available room.
You can now keep a small physical decision in code without drawing every bend. Continue with differential pairs, or use the Routing and Route options references for the full chain and rule precedence.