Nodes/SBL/Math Scratchpad
ComfyUI Node

Math Scratchpad

The scratchpad that answers 'how many frames do I need' before you generate

By SoftByteLabs·Created 2 months ago·Updated 2 months ago· 1
Math Scratchpad
      ◄expressionsimport math t = 12 rawframes = t * 24 + 1 ltxframes = 8 * math.floor((rawframes - 1) / 8) print(ltxframes + 1) print(ltxframes / 24) print(ltxframes / 8)►

      Video workflows have a problem that still images never had: the arithmetic. "I want 12 seconds at 24fps, and LTX wants the frame count aligned to 8, so what do I actually put in the node?" SBL_MathScratchpad is the node you drop into the graph while you figure that out - a proper little programming scratchpad with an input pane on top, an output pane below, and nothing else. No outputs to wire, because it's not meant to feed anything. It's a place to think out loud in math before you commit numbers to the real nodes.

      It uses the same restricted AST interpreter as SBL's Math Evaluator (safe, no exec()/eval(), allow-listed functions and imports), but it runs as a full program: variables, functions, loops, comprehensions - and it captures print() output to the on-screen panel. The default example is pure LTX-Video frame math, and it's genuinely the thing you'll type:

      import math
      t = 12
      rawframes = t * 24 + 1
      ltxframes = 8 * math.floor((rawframes - 1) / 8)
      print(ltxframes + 1)
      print(ltxframes / 24)
      print(ltxframes / 8)
      

      Change t, hit Run, and you get your frame count, your seconds, and your alignment factor printed right there. LTX-2's default is 24fps and the model wants frame counts it can tile, which is exactly why this packs a multiple-of-8 example - and why the answer to "how many frames" is rarely the number you first type.

      How it works

      Under the hood it's an OUTPUT_NODE whose frontend swaps the plain textarea for a two-pane DOM widget. When you hit Run, the JavaScript POSTs your expressions to a route the pack registers on ComfyUI's server (/sbl/scratchpad/evaluate), the interpreter executes them with output capture on, and the printed lines come back into the bottom pane. Errors - syntax slips, a banned import, an over-long loop - come back as red text in that same pane instead of killing your queue.

      Common gotchas

      • Assignments alone show nothing. The scratchpad displays what you print(), not what you assign. Forgetting print() is the most common "it's broken" moment, and it isn't broken.
      • It's deliberately not Python. import os, file writes, and anything network-ish get refused. You're meant to compute numbers, not run a server.
      • Loops have guardrails. Iteration and while counts are capped (100k total iterations, 10k per while), so an accidental infinite loop turns into an error message instead of a frozen UI.

      Install

      One install for the whole SBL pack: ComfyUI Manager → search SBL, or clone https://github.com/SoftByteLabs/SBL into ComfyUI/custom_nodes and restart. No extra pip dependencies, no models to download - the only moving part is the small server route it adds, which is why the node is interactive rather than a one-shot text box.

      CategorySBL

      Inputs (1)

      NameTypeDefaultDescription
      expressionsSTRINGimport math t = 12 rawframes = t * 24 + 1 ltxframes = 8 * math.floor((rawframes - 1) / 8) print(ltxframes + 1) print(ltxframes / 24) print(ltxframes / 8)—

      Outputs (0)

      No outputs