Nodes/TJ_ComfyUI_Lineart2Vector/SVG Visibility Toggle
ComfyUI Node

SVG Visibility Toggle

Show, hide, or delete layers in your vector

By TJ16th·Created 10 months ago·Updated 10 months ago· 2
SVG Visibility Toggle
    • svg
    • meta
    svg_string
    visibility_rules_json[]
    default_visibletrue
    remove_hiddenfalse

    Sometimes the fix for a bad vector isn't recoloring or reordering - it's that a path shouldn't be there at all. SVG Visibility Toggle hides or removes SVG elements by selector. One rule like {"selector": "#path7", "visible": false} and that stray contour that's been wrecking your output is gone from the render. It's the simplest editor in the pack and one of the most useful, because vectorized line art almost always contains junk you want out.

    How it works

    Inputs are svg_string plus two rule options:

    • visibility_rules_json (default []) - array of {selector, visible} pairs using the pack's standard selectors: #id, .class, [attr*=value]. The README's example is illustrative: {"selector": "#path0", "visible": true}, {"selector": ".shadow", "visible": false}, {"selector": "[id*=bg]", "visible": false}.
    • default_visible (default true) - the visibility for anything not mentioned in your rules. Flip it to false and you've inverted the logic: everything hides except what you explicitly keep.
    • remove_hidden (default false) - the decision that matters. false sets display:none on hidden elements (they stay in the file, just invisible); true deletes them from the SVG entirely. The tooltip spells out the difference.

    Outputs: svg (filtered string) and meta (JSON - which elements were hidden/removed, so you can confirm the rules matched what you thought).

    When to use hide vs. remove

    display:none is non-destructive and reversible - hide a layer now, and a later visibility node can re-show it. It also keeps the file's path numbering intact, which matters if you're styling by index afterward. remove_hidden physically strips the elements out, which shrinks the file and guarantees downstream nodes (laser cutters, plotters) can't accidentally render them - but it renumbers the world: any index-based rules you wrote against the old numbering are now pointing at different paths. Rule of thumb: hide for iteration and layer experiments, remove for the final export when you're sure the junk is junk.

    Where it fits

    The classic workflow: vectorize → clean up → SVG Group Layout with labels to identify the offender (that's what labels are for) → Visibility Toggle to hide or delete it → reorder + restyle the survivors. It's also a legit layer system: keep all your paths in one SVG and use visibility rules to build a "version A" vs. "version B" of a design from the same source file.

    Install

    Standard pack install - one package, all nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TJ16th/TJ_ComfyUI_Lineart2Vector.git
    # restart ComfyUI
    

    or ComfyUI Manager → search TJ_ComfyUI_Lineart2Vector. No models, no keys. Pure XML manipulation under the hood, so the pack's heavier dependencies are irrelevant to this node - it just needs the pack installed and ComfyUI restarted.

    Where people get burned

    The meta output exists because silent no-match is the #1 failure: a selector typo hides nothing and you stare at an unchanged render wondering why. Check meta. Second: forgetting that default_visible affects everything not in your rules - if you only list one rule and set it false, you've hidden the entire SVG except that one path. Third: the renumbering gotcha above - remove elements before doing index-based styling, never after, or every path_indices string you wrote goes stale.

    CategoryTJ_Vector

    Inputs (4)

    NameTypeDefaultDescription
    svg_stringSTRING
    visibility_rules_jsonoptSTRING[]Array of {selector, visible} to control element visibility
    default_visibleoptBOOLEANtrueDefault visibility for elements not specified in rules
    remove_hiddenoptBOOLEANfalseRemove hidden elements from SVG (true) or set display:none (false)

    Outputs (2)

    NameTypeDescription
    svgSTRING
    metaSTRING