ComfyUI Node

Box Range

Draw a box on the canvas, get the numbers out

By Trung0246·Created 3 years ago·Updated about a year ago· 137
Box Range
  • box_range
  • _data
script_box_regex(?P<x>^x$)|(?P<y>^y$)|(?P<w>^width$)|(?P<h>^height$)|(^@x$)|(^@y$)|(^@w$)|(^@h$)|(^%x$)|(^%y$)|(^%w$)|(^%h$)
script_orderbox

Box Range is a visual widget node: you drag and resize a box right on the node, and it turns that box into the x, y, width, height numbers that a ton of ComfyUI nodes silently want. The author's description says it best - "visualization of boxes. useful for anything that requires boxes." And there's a delightful instruction in there: "Double click on each corner and discover what each will do."

It started life as a helper for ConditioningSetAreaPercentage-style nodes (anything with percentage-sized x,y,width,height inputs), then got reworked into something more general: it now outputs plain int and float data based on a regex, so the box can feed inpainting crops, area conditioning, cutout logic, whatever. If you've ever hand-typed coordinates into a "set area" node and squinted at the result, this is the node that shows you where the area actually is.

How it works

The box_range widget defines the box and the drawing grid (row_count, col_count, ratio width/height, flex settings for sizing). The script_box_regex then decides what values come out by matching named groups against pin names. The default regex matches x, y, w (width), h (height) - plus @-prefixed and %-prefixed variants:

  • plain x, y, w, h - absolute pixel values
  • @x, @y, @w, @h - values exposed as script data (for the pack's Script system)
  • %x, %y, %w, %h - direct outputs

The source supports a fuller key list you can reach with regex tweaks: W/H (canvas dims), S8W/S8H (snapped to multiples of 8 - the classic ComfyUI resolution constraint), R (aspect ratio), A (area), px/py/pw/ph (normalized 0–1), and s8x/s8y/s8w/s8h (pixel values snapped to multiples of 8).

The inputs and outputs

  • box_range - the interactive box widget. Draw first, read numbers after.
  • script_box_regex - which named values to emit (default: x,y,w,h and their @/% variants).
  • script_order - ordering for script-mode outputs, default "box".
  • _data - the output pin(s); you get one per matched key.

How to install it

The usual:

cd ComfyUI/custom_nodes
git clone https://github.com/Trung0246/ComfyUI-0246

restart, or ComfyUI Manager → search "ComfyUI-0246". No models.

Common issues & troubleshooting

No outputs appear. Your regex doesn't match any of the supported keys - either the pin names don't line up or you typed a key the node doesn't know. Start from the default regex and edit one group at a time.

Values are off by a factor or not snapped. The plain x/w outputs are absolute pixels; if a downstream node wants normalized (0–1) values, use the p-prefixed groups (px, pw...), and if it needs 8-aligned dimensions (most latent-space nodes do), use the s8 groups. Mismatching these is the classic Box Range gotcha.

Nothing changes when I double-click. Double-click the corners of the box - the author's hint - not the node body. The corner handles are the discovery UI.

As ever with this pack: single-author, dormant since early 2025, no active maintenance. Box Range is one of the more polished, self-contained nodes in it, though, and its core trick (draw the box, read the numbers) is unlikely to break on a ComfyUI update.

Category0246

Inputs (3)

NameTypeDefaultDescription
script_box_regexSTRING(?P<x>^x$)|(?P<y>^y$)|(?P<w>^width$)|(?P<h>^height$)|(^@x$)|(^@y$)|(^@w$)|(^@h$)|(^%x$)|(^%y$)|(^%w$)|(^%h$)
script_orderSTRINGbox
box_rangeBOX_RANGE

Outputs (1)

NameTypeDescription
_data*