Nodes/kubakub nodes/kubakub regions to svg / pdf / dxf
ComfyUI Node

kubakub regions to svg / pdf / dxf

Regions out as SVG, PDF or DXF — for a plotter, a laser, or Illustrator

By kubakubkub·Created about a month ago·Updated 2 days ago· 10
kubakub regions to svg / pdf / dxf
  • regions
  • mask
  • matrix
  • preview
  • files
  • report
◄modeoutline►
◄width_mm0.0►
◄simplify_px1.0►
◄corner_deg35►
◄min_area_px16►
◄spur_px6.0►
◄kerf_mm0.00►
◄svgtrue►
◄pdftrue►
◄dxftrue►
◄filename_prefixregions►
◄select►
◄folder►

Here's a job nobody expects from a ComfyUI pack: turning the regions you built for a projection show into cutting files. The floor-1 windows you segmented become an SVG with one group per region group and region names as path ids; the same selection becomes a DXF your laser software can open, or a PDF where every group is an Illustrator layer.

The reason this is more useful than it sounds is that regions are already a traced partition of an image. You did the hard part when you built them. This node just writes them out.

Two modes, two different products

outline (default) - each region as filled paths with its holes. The tracer walks the pixel edges, so the geometry is exact rather than approximate: a 40×40 px square comes out exactly 1600 px of area. Then simplify_px (1 by default) drops points that deviate less than that from the pixel outline. Vertices that turn more than corner_deg (35°) stay corners - so straight edges stay straight, which is the property that makes this usable for architecture - and everything else becomes cubic Beziers. corner_deg 180 disables curves entirely and gives you polygons, which is what you want for a laser.

Parts that touch only at a corner pixel stay separate outlines, and min_area_px (16) drops specks and holes.

centerline - the skeleton of the shape as single open lines, with side branches shorter than spur_px (6) removed. That's a plotter, a laser, or an engraving pass: one line to travel along, not a shape to fill. The lines are ordered by nearest-neighbour from the top-left so the tool travels short distances instead of doing an interpretive dance across the material - the README cites 42,000 lines of a festival line drawing ordered in 4 seconds, which is why that detail is in there. Add spur_px if you're getting hairs, and raise it if the letterforms break up.

Real millimetres, and kerf

width_mm is the one that makes this a fabrication node instead of a graphics one: set it to the real width of the thing and every coordinate in the output is in millimetres at one uniform scale. Leave it at 0 and you're in pixels.

With width_mm set, kerf_mm becomes available - and it's ignored without width_mm, because pixels have no millimetres. Kerf grows (+) or shrinks (−) every outline by half the value, with mitred corners, which is exactly how you compensate for a laser's cut width. Measure your kerf with a test cut, don't guess it.

Files

Three switches, all on by default: svg (groups = region groups, ids = region names - so your Illustrator file arrives organised), pdf (one optional-content group per region group, which Illustrator shows as layers), dxf (R12, one layer per group, closed polylines for outlines and open ones for centrelines, y flipped, curves flattened). filename_prefix starts the file names and accepts a subfolder like sub/name; a counter is appended and earlier files are never overwritten. folder empty writes to ComfyUI/output/kuba_vector.

This is one of the few nodes in the pack that is an output node - queue the graph and the files appear. Nothing to wire downstream.

What to connect

Either regions (a KUBA_REGIONS from any regions node) or a plain mask, with the plan-syntax select narrowing the regions. With a mask connected, regions and select are ignored and the mask is vectorised instead - which is the route when you've painted a line layer by hand and want it as a cutting path. preview draws the vector paths over the matrix background so you can see what you're about to cut, and files lists the written paths. The report gives you the region and path counts, the size in pixels or millimetres, the total line length for centrelines, and the file list. Check the report before sending anything to a machine that costs money to run.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/kubakubkub/ComfyUI_KubaNodes
python -m pip install -r ComfyUI_KubaNodes/requirements.txt

Manager → kubakub nodes. ComfyUI 0.37.0+, OpenCV by default - but this is the node with an important optional dependency: shapely is needed for outlines and scikit-image for centrelines. They're deliberately not in requirements.txt (one package per feature, no bloat), and the console says so at startup: [Kub] not installed (only these features are off): regions to vector (outlines) -> pip install shapely. If the node runs and produces nothing, that line is why.

python -m pip install shapely scikit-image

Model-free test: tests/test_vector.py.

Notes

The trace is of the pixel mask, not the original curve. If your region came from a rasterised Illustrator layer or a SAM mask, the vector you get back is that raster's edge. Fine for cutting; don't expect it to recover the client's original path data.

select uses the same selector syntax as regions to mask - W_F1_*, group:Windows, tag:..., comma for OR, space for AND, ! for NOT. So "cut me the windows" is one line.

Categorykubakub/2d/regions

Inputs (16)

NameTypeDefaultDescription
modeCOMBOoutlineoutline: filled shapes per region (Illustrator, After Effects). centerline: single lines through the middle (plotter, laser, engraving).
width_mmFLOAT0.00–1000000Real width of the whole image in mm (one uniform scale); 0 = pixels.
simplify_pxFLOAT1.00–50Largest deviation from the pixel outline when simplifying.
corner_degFLOAT350–180outline: vertices turning more than this stay corners; 180 = no curves.
min_area_pxFLOAT160–1000000Drop specks and holes smaller than this.
spur_pxFLOAT6.00–1000centerline: drop side branches shorter than this.
kerf_mmFLOAT0.00-100–100outline in mm: grow (+) or shrink (-) every outline by kerf / 2. Ignored when width_mm is 0 (pixels have no millimetres).
svgBOOLEANtrueWrite an .svg (groups = region groups, ids = region names).
pdfBOOLEANtrueWrite a .pdf with one layer per region group.
dxfBOOLEANtrueWrite a .dxf for CAD, CNC and laser software.
filename_prefixSTRINGregionsStart of the file names (a number is added, earlier files are kept); 'sub/name' writes into a subfolder.
regionsoptKUBA_REGIONSThe regions to vectorise (from any kubakub regions node).
maskoptMASKVectorise a mask instead (e.g. a painted line layer).
selectoptSTRINGThe regions that are drawn. Empty = all. Not used when a mask is connected. Written as in kubakub region plan: names with wildcards ('W_F1_*'), 'group:Windows', 'tag:front', 'region:3-7'; comma or Enter = or, space = and, '!' = not.
folderoptSTRINGWhere to write; empty = ComfyUI output/kuba_vector.
matrixoptIMAGEPreview background.

Outputs (3)

NameTypeDescription
previewIMAGEThe vector paths drawn over the matrix.
filesSTRINGThe written files, one per line.
reportSTRINGRegions, paths, size in px or mm, line length for centerlines, and the written files.