Nodes/ComfyUI_SVG-Suite/SVG Element Selector
ComfyUI Node

SVG Element Selector

The inspector tool for SVGs you didn't create

By MushroomFleet·Created about a year ago·Updated 5 months ago· 9
SVG Element Selector
    • STRING
    • INT
    ◄svg_string—►
    â—„selectorpathâ–º
    â—„output_typeelement_countâ–º
    â—„attribute_filterâ–º

    Every SVG you didn't hand-write is a mystery box. How many paths are in there? Do the shapes even have IDs? Is that green a fill or a stroke? SVG Element Selector is the flashlight - it parses the SVG, finds elements matching a selector, and reports on them. It's the reconnaissance node that tells you whether the rest of your editing pipeline is even feasible.

    What it reports

    Give it an svg_string, a selector (a tag name like path, circle, rect), and an output_type:

    • element_count - "how many match." The default, and genuinely the most useful for planning.
    • element_ids - lists every ID (or [no-id] for the unfortunates). This is how you find out whether the file uses IDs at all before you try ID-based editing.
    • element_classes - the class names in use.
    • element_attributes - full attribute dump per element (Element 0: path - d="..." fill="#FF0000"). The forensic mode.
    • selected_elements - the raw markup of matching elements.

    You can also narrow with attribute_filter, either fill=#FF0000 (exact value) or just fill (attribute exists). That turns the node into "show me every element with a fill attribute," which is perfect for auditing color work before you run a replacer.

    Two outputs

    The node returns both a STRING (the human-readable report) and an INT (the match count). The count output is the sneaky useful one - you can wire it into a condition or use it to decide whether your selector actually hit anything before you bother piping the SVG onward. This is one of the few svg-suite nodes with a numeric output, and it makes it scriptable in a way the pure-string nodes aren't.

    Install

    Pack standard:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MushroomFleet/svg-suite
    pip install -r requirements.txt
    

    Restart ComfyUI, or via Manager under "svg-suite". Uses lxml from the pack requirements.

    Where people get burned

    The selector is a tag name, not a full CSS selector language - path works, path.special won't. If the file uses namespaced tags (some exports do), matching can get finicky. And the reports are text: don't expect structured JSON out of this for downstream automation - if you need parsed structure, the element_attributes text is meant for your eyes, not for a parser.

    One more: a converted SVG with no IDs and no classes will make element_ids and element_classes return nothing but [no-id] lines. That's not the node failing - it's telling you the file lacks hooks, and you should add them (via SVG Attribute Manipulation's add_class / add_attribute) before trying selector-based editing downstream.

    Category💎TOSVG/XMLParser

    Inputs (4)

    NameTypeDefaultDescription
    svg_stringSTRING—
    selectorSTRINGpath—
    output_typeCOMBOelement_count5 options: element_count, element_ids, element_classes, element_attributes, selected_elements
    attribute_filteroptSTRING—

    Outputs (2)

    NameTypeDescription
    STRINGSTRING—
    INTINT—