Nodes/ComfyUI WPX Nodes/DetermineRowsAndCols
ComfyUI Node

DetermineRowsAndCols

Let a calculator pick your grid rows and columns

By WangPengxing·Created 2 years ago·Updated 2 years ago· 0
DetermineRowsAndCols
    • Rows
    • Cols
    num12
    num22
    total_count10

    DetermineRowsAndCols is the smallest node in the ComfyUI WPX Nodes pack, and it doesn't touch a single pixel. It's a pure arithmetic utility: you tell it roughly how many rows and columns you'd like, and how many items you actually have, and it returns the grid dimensions that fit. No image in, no image out - just two integers. It exists to answer the question the pack's other nodes keep making you answer by hand: "I have 10 stickers, what rows × cols grid should I use?"

    How it works

    The logic is deliberately simple, and reading the three cases tells you exactly what it's doing. With your two guesses (num1, num2) and the real count (total_count):

    • If num1 × num2 would be a perfect square equal to total_count, it returns a square grid.
    • Otherwise, if a num1 × num2 rectangle is large enough to hold total_count, it returns the wider layout - (max, min).
    • If even that's too small, it just returns max × max, which over-provisions rather than under-fits.

    In practice: feed it "around 3 × 3, and I have 10 elements" and it hands back the Rows and Cols that actually fit. It's not clever, and it doesn't need to be.

    The inputs

    Three INTs:

    • num1 (default 2) and num2 (default 2) - your preferred rows and columns guesses.
    • total_count (default 10) - how many cells/elements you actually have.

    Outputs: Rows and Cols, both INT. That's the whole node.

    Where it slots in

    The natural target is PenetrateStyle, which takes rows and cols for its sticker-sheet layout - wire these two outputs straight into those inputs and you stop doing grid math in your head. It's also handy for any image-grid or batch-arrangement node that takes explicit rows and columns. That said, it's a thin utility with a narrow job. If you only ever arrange grids by hand, skip it; if you're building a reusable workflow that others will load, a node that computes the grid beats asking people to read your mind.

    Installing

    ComfyUI Manager → search "ComfyUI WPX Nodes" → install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/WangPengxing/ComfyUI_WPX_Node
    # restart ComfyUI
    

    No models, no dependencies beyond what the pack already needs. The one real install note is pack-wide: the pack imports rtree and scipy at startup, and if either is missing, none of the eight WPX_Node nodes appear - including this one. pip install rtree scipy and restart.

    Gotchas

    Honestly, there's not much to troubleshoot here - it's three integers and an if-statement. One expectation to set: it's a quick heuristic, not a layout optimizer. If your num1/num2 guesses are wildly off, it can return a grid that's larger than you wanted, and it has no sense of aspect ratio. It picks a fitting shape, not a pretty one. For that role, it's fine - and it's about as simple as a node gets.

    CategoryWPX_Node

    Inputs (3)

    NameTypeDefaultDescription
    num1INT21–10
    num2INT21–10
    total_countINT101–50

    Outputs (2)

    NameTypeDescription
    RowsINT
    ColsINT