English | 日本語 | 繁体中文
- Top
- Node / Image Node / Text Node / XYPlot Node / Float Palet
- Workflow
# Node
## :tomato: Text Node
### D2 Regex Replace
- Can replace using regular expressions
- Multiple conditions can be specified
- Supports reuse of regex match strings (e.g., \1, \2)
- Target string can be specified by "tag unit" or "whole"
#### Input
- `text`
- Target string for search
- `mode`
- `Tag`: Break down `text` by newlines and "," and replace individually
- `Advanced`: Replace `text` as a whole
- `regex_and_output`
- List of search strings and output strings
- Write in following format
- If output string is empty, matched part is deleted
- No limit on number of entries
```
Search string 1
--
Output string 1
--
Search string 2
--
Output string 2
```
#### Output
- `text`
- Text after replacement
#### Sample
Sample for removing Pony series quality tags.
Mode: `Tag`
Input text
```
score_9, score_8_up, (score_7_up, score_6_up:0.8) , rating_explicit, source_anime, BREAK
1girl, swimsuit
```
Regex Replace
```
.*(score_|rating_|source_).*
--
--
BREAK
--
```
Output text
```
1girl, swimsuit
```
---
### D2 Regex Switcher
- Searches input text with regex and outputs matching text
- Main purpose is switching quality tags per Checkpoint
- When matching string is found in input `text`, outputs target string and match index (starting from 0)
- Can concatenate strings at front and back
#### Input
- `text`
- Search target string
- `prefix`
- String to concatenate at front
- `suffix`
- String to concatenate at back
- `regex_and_output`
- List of search strings and output strings
- Write in following format
- `pre_delim`
- Character inserted between `prefix` and `regex_and_output`
- `Comma`: `,` / `Line break`: newline / `None`: nothing
- `suf_delim`
- Character inserted between `regex_and_output` and `suffix`
#### Output
- `combined_text`
- String combining `prefix` + output string + `suffix`
- `prefix` / `suffix`
- Input passthrough
---
### D2 Multi Output
- Node that outputs generic parameters like seed and cfg as lists
#### Input
- `type`
- `FLOAT`: Floating point numbers. For CFG etc.
- `INT`: Integers. For steps etc.
- `STRING`: Strings. For sampler etc.
- `SEED`: Can input seed values with random number button
- `Add Random`
- Adds random numbers to input field
- Only shown when `type` is `SEED`
### Output
- `x / y_items`
- Plain line-break separated text
- Used with `D2 XY Plot`, `D2 XY Plot Easy`, `D2 XY Plot Easy Mini`
- `LIST`
- Splits by line break and outputs the items one by one. The connected node runs once per item
- `ARRAY`
- Splits by line break and outputs as an array
---
### D2 List Converter
- A node that converts between `LIST` (ComfyUI's list, which outputs items one by one) and `ARRAY` (ComfyUI's built-in Array type, which outputs an array as a single value), and also converts them to a string
- Combines the features of `D2 List To String` and `D2 XY List To Plot`
#### Input
- `LIST` / `ARRAY`
- Value to convert. Connect either one
- When both are connected, they are joined in the order `LIST` → `ARRAY`
- `separator`
- Delimiter for the `STRING` output
- `Comma + Space`: Join with `, `
- `Comma`: Join with `,`
- `Line break`: Join with line breaks
- `Semicolon`: Join with `;`
- `Space`: Join with a space
- `None`: Join with no delimiter
#### Output
- `x / y_items`
- Line-break separated text. Used with `D2 XY Plot`
- Line breaks inside each item are removed
- `LIST`
- Outputs the items one by one
- `ARRAY`
- Outputs as an array
- `STRING`
- Text joined with `separator`
- Line breaks inside each item are kept
---
### D2 List To String
Deprecated. Please use `D2 List Converter` instead.
---
### D2 Text Concat
- Text concatenation node with an adjustable number of inputs
- Adjust the number of input fields with `text_count`, then join the texts connected to `text_1` .. `text_N`
- `separator` is shared with `D2 List To String`
#### Input
- `text_count`
- Adjusts the number of input fields (1 to 50)
- `separator`
- `Comma + Space`: Join with `, `
- `Comma`: Join with `,`
- `Line break`: Join with line breaks
- `Semicolon`: Join with `;`
- `Space`: Join with a space
- `None`: Join with no delimiter
- `skip_empty`
- When `true`, skips unconnected or empty (whitespace/line-break only) inputs
- Prevents stray delimiters (`, , `) from appearing
---
### D2 Filename Template / D2 Filename Template2
- A node for creating string templates by incorporating date and parameters from other nodes
- `D2 Filename Template2` is a version that supports multiple lines
- It is also possible to retrieve values from arrays, dictionaries, and objects
- Preset feature for commonly used formats like Stable Diffusion webui A1111-style metadata
- You can add presets by editing `custom_nodes/d2-nodes-comfyui/config/template_config.yaml`
#### Input
- `arg_{number}`
- Import values from other nodes
- `format`
- `%date:{yyyy/MM/dd/hh/mm/ss}%`
- `yyyy`: Year
- `MM`: Month
- `dd`: Day
- `hh`: Hour
- `mm`: Minute
- `ss`: Second
- `%{node name}.{key}%`
- Retrieves values by specifying node name and item name
- Example: `%Empty Latent Image.width%`: Get width from the Empty Latent Image node
- `%node:{id}.{key}%`
- Retrieves values by specifying node ID and item name
- Example: `%node:8.width%`: Get width from node ID 8
- `%arg_{number}%`
- Embed input values
- `%arg_{number}:ckpt_name%`
- Embed checkpoint name with `.safetensors` removed
- `%arg_{number}:preset.{preset_name}%`
- Presets can be added by editing `custom_nodes/d2-nodes-comfyui/config/template_config.yaml`
- `%exec_{number}[{index}]%`
- Retrieves the value at `{index}` from the **array** input to `arg_{number}`
- `%exec_{number}['{key}']%`
- Retrieves the value for `{key}` from the **dictionary** input to `arg_{number}`
- `%exec_{number}.{key}%`
- Retrieves the value for `{key}` from the **object** input to `arg_{number}`
- `arg_count`
- Increase or decrease the number of input items
- `normalization`
- Filename sanitization option
Retrieving node information connected to `arg_N`, using the node name, etc.Retrieving `steps` and `sampler_name` from the `d2_pipe` object, which summarizes generation parameters.Using the preset `a1111` with the value input to `arg_1`. Using `D2 Pipe` to add the checkpoint name.
---
### D2 Prompt
- You can select LoRA from the `CHOOSE` button and insert an A1111-style LoRA prompt
- Delete comments in text
- Targets lines starting with "#", lines starting with "//", and text between "/*" and "*/"
- Displays token count at the bottom (works when `token_count` is `true`)
- Uses "ViT-L/14" CLIP for token count measurement. Please use `D2 Token Counter` if you want to use other CLIP models
#### About Comment Shortcut Keys
- Comment shortcut key (ctrl + /) is available in all text boxes
- Shortcut keys can be changed in `Settings > D2 > shortcutKey`
- Delete the content above if you want to disable it
---
### D2 Prompt Sanitizer
- A node that cleans up prompt strings
- Converts `_` (underscore) to a space (`long_hair` → `long hair`)
- Ensures a single space after each `,` (comma) and tidies up surrounding whitespace (`a , b` → `a, b`)
- Collapses redundant consecutive commas and removes commas at the start of a line (`a,, ,b` → `a, b`)
- Can also convert line breaks, remove duplicate tags and remove comments
- Each transformation can be toggled on / off individually
#### Input
- `underscore_to_space`: Convert `_` to a space
- `space_after_comma`: Tidy the whitespace around commas and normalize it to `, ` (line breaks are preserved)
- `remove_extra_comma`: Collapse redundant consecutive commas (`,,` / `, ,`) into one and remove commas at the start of a line (line breaks are preserved)
- `protect_lora`: Protect LoRA notation enclosed in `<...>` from conversion (keeps the underscores in ``)
- `protect_score`: Protect Pony quality tags such as `score_9` / `score_8_up` from conversion
- `newline_mode`: How to convert line breaks
- `keep`: Do nothing (preserve line breaks)
- `add_comma`: Append `,` to the end of each line (line breaks preserved; empty lines and lines already ending with `,` are left as-is)
- `to_comma`: Convert line breaks to `,` and join into a single line
- `to_space`: Convert line breaks to a space
- `remove`: Remove line breaks (`1girl\nsmile` → `1girlsmile`; useful for joining Japanese text)
- `remove_duplicate_tags`: Remove duplicate tags (keeps the first occurrence; comparison ignores `_` vs. space differences and letter case)
- `strip_trailing_comma`: Remove a comma at the very end of the whole string (useful together with `add_comma`)
- `comment_type`: Which comment styles to remove. Same as `D2 Prompt`
- `# + // + /**/`: Remove lines starting with `#`, lines starting with `//`, and everything between `/*` and `*/` (can span multiple lines)
- `# only` / `// only` / `/* */ only`: Remove only that style
- `None`: Do nothing (default)
> The transformations run in this order: remove comments → remove duplicate tags → convert line breaks → convert underscores → remove extra commas → normalize commas → strip trailing comma. Any `,,` left behind by `remove_duplicate_tags` is cleaned up by `remove_extra_comma`, so turning both on gives a tidy result.
---
### D2 Convert NAI Prompt
- Converts prompt weights between StableDiffusion and NovelAI
- Performs the same conversion as the `Prompt convert dialog` inside a workflow
- A weight's range ends at a line break (conversion never spans lines)
- Does not tidy up duplicate commas or whitespace. Connect `D2 Prompt Sanitizer` after it if needed
#### Input
- `prompt`: The prompt to convert (input only)
- `convert`: Conversion direction
- `sd_to_nai`: StableDiffusion format → NovelAI format
- `nai_to_sd`: NovelAI format → StableDiffusion format
- `mode`: NovelAI weight notation
- `number`: Numeric format (`1.2::aaa ::`)
- `brace`: Brace format (`{{aaa}}` / `[[aaa]]`). Tags with a weight of 0 or less cannot be expressed with braces, so only those tags are output in numeric format
- `remove_negative`: Only effective with `nai_to_sd` and `number`. Removes tags with a negative weight
- Commas around removed tags are kept (`-2::aaa::, 1.2::bbb::` → `, (bbb:1.2)`)
- Tags with a weight of 0 are not removed (a weight of 0 still affects the generated image)
#### Numeric format conversion rules
- `sd_to_nai` always puts a space before the closing `::` (`(aaa5:1.2)` → `1.2::aaa5 ::`). This prevents the `5::` in `aaa5::` from being misread as the start of a weight
- `nai_to_sd` also handles a missing closing `::`. An unclosed weight extends until the start of the next weight or the end of the line
- `1.2::blonde hair, 1.3::from side::` → `(blonde hair:1.2), (from side:1.3)`
- `1.2::aaa, bbb::` → `(aaa, bbb:1.2)` (a weight applied to multiple tags is kept as is)
- Negative weights are written with the minus sign before the number, like `(aaa:-2)`
---
### D2 Moss Item / D2 Moss Prompt
- Nodes for building layout prompts (JSON format) for the image generation model [MOSS-Image](https://github.com/OpenMOSS/MOSS-Image)
- The area of a mask is used as the position (bbox) where an element is placed
- The bbox coordinates (pixel coordinates with the canvas center as the origin) are calculated automatically, so you don't need to calculate them by hand. The layout follows when you change the resolution
- Connect them in the order `D2 Create Masks` → `D2 Moss Item` → `D2 Moss Prompt`
- Layout prompts are an experimental feature of MOSS-Image, so only the fields described in the [USERGUIDE](https://github.com/OpenMOSS/MOSS-Image/blob/main/USERGUIDE.md) are supported
#### D2 Moss Item
- Creates one element of the layout
- The rectangle that encloses the non-zero area of the mask becomes the bbox. If the mask is empty, the whole canvas becomes the bbox
##### Input
- `mask`: Mask of the area where the element is placed
- `label`: Type of the element
- `object`: Draw an object, a person, etc.
- `text`: Draw text
- `caption`: Description of how the element looks (size, style, position, etc.)
- You can comment out text the same way as in `D2 Prompt` (lines starting with `#` / `//`, `/*` … `*/`)
- `text`: The text to draw. Used only when `label` is `text`
- To insert a line break, type `\n` or connect another node (such as `D2 Prompt`)
##### Output
- `moss_item`: Data for one element. Connect it to `D2 Moss Prompt`
#### D2 Moss Prompt
- Combines a description of the whole image and multiple `moss_item` inputs into a JSON string prompt
##### Input
- `meta`: Tags describing the type of image. Multiple tags can be entered, separated by commas
- Examples: `poster` / `photograph` / `illustration, anime`
- `canvas_type`: Usually leave it as `single`
- `summary_caption`: Description of the scene and art style of the whole image
- Comments can be used the same way as in `caption`
- `item_count`: Number of `moss_item` inputs
- `moss_item_{number}`: Connect `D2 Moss Item`
##### Output
- `prompt`: JSON string of the layout prompt. Connect it to a text encoder
> If `meta` / `canvas_type` / `summary_caption` are left empty, they are omitted from the JSON.
---
### D2 Token Counter
- Counts tokens in prompts
---
### D2 Load Text
- A general-purpose node that loads a text file
- For batch-editing training captions, use it to read the path obtained by `D2 Folder Image Queue` with `*.txt`
#### Input
- `file_path`
- Full path of the text file to load
- `encode_to_utf8`
- `true`: Auto-detect the character encoding and convert to utf-8 when reading
- `false`: No conversion (read as utf-8)
#### Output
- `text`
- The file content (returned as-is, no formatting; empty string if the file does not exist)
- `file_path`
- Passes through the input `file_path` (for feeding into `base_filename` of `D2 Save Caption`)
---
### D2 Load CSV
- A node that loads a CSV / TSV file and extracts a range of rows and columns
- Data with commas (like prompts) is assumed to be double-quoted (standard CSV escaping)
- To keep memory bounded even for large files, there is a single output whose format is switched by `output_mode`
#### Input
- `file_path`
- Full path of the file to load
- `file_type`
- `csv`: comma-separated / `tsv`: tab-separated. The delimiter of the input file
- `encode_to_utf8`
- `true`: Auto-detect the character encoding and convert to utf-8 when reading
- `output_mode`
- `list`: Output as a 2D array
- `csv`: Output as line-break + comma separated text
- `row_index` / `column_index`
- Range of rows/columns to output (1-based). Empty means all
- `3`: only the 3rd row (column)
- `2-`: from the 2nd row (column) to the end
- `-4`: rows (columns) 1 to 4
- `2-4`: rows (columns) 2 to 4
- A malformed format (`0`, `2--4`, non-numeric, etc.) stops execution with an error (so wrong data is not passed on)
- `use_doublequote`
- When `output_mode:csv`, double-quote every cell
- `false` produces a plain comma join, so cells containing commas lose their separation (`"AAA,BBB","XXX,YYY"` -> `AAA,BBB,XXX,YYY`)
#### Output
- `output`
- The selected data. A 2D array or text depending on `output_mode`
- `lines_count`
- Number of rows in the selected range
- `file_path`
- Passes through the input `file_path`
---
### D2 Save Caption
- A node that formats tags and saves a caption file
- Saves to the path obtained by replacing the extension of `base_filename` with `extension` (e.g. `d:/images/aaa.jpg` -> `d:/images/aaa.txt`)
- Formatting runs in this order: split -> trim -> unify separator -> remove escape -> exclude -> dedupe -> prepend -> trailing comma
#### Input
- `base_filename`
- The source path for saving. Receives `image_path` of `D2 Folder Image Queue` or `file_path` of `D2 Load Text`
- Stops with an error if empty (to prevent saving to an unintended location)
- `text`
- The caption body (from `WD14 Tagger` or `D2 Load Text`)
- `extension`
- Extension of the file to save (e.g. `txt`)
- `exclude_tags`
- Tags to exclude. Separated by both commas and line breaks
- Writing `regex/pattern/` excludes tags matching the regular expression (exclude only)
- Bracket escaping is ignored in the comparison (a prompt tag `rem_\(re:zero\)` can be excluded by an exclude tag `rem_(re:zero)`)
- `prepend_tags`
- Tags to prepend. Comma-separated. Tags that already exist are not added
- `word_separator`
- Unify the word separator (to align a mix of `blue eyes` and `blue_hair`)
- `underscore` (default): Unify spaces to `_` (`blue eyes` -> `blue_eyes`)
- `space`: Unify `_` to spaces (`blue_hair` -> `blue hair`)
- `none`: No conversion
- `remove_escape`
- `true`: Strip bracket escaping (`\(` `\)` `\[` `\]`) from the output tags (`rem_\(re:zero\)` -> `rem_(re:zero)`). For training captions
- `trailing_comma`
- `true`: Add a trailing comma
- `ignore_case`
- `true`: Ignore case when matching for exclusion
- `backup`
- `true`: If a file of the same name exists, rename the old file to `.bak` before saving
- `dry_run`
- `true`: Do not save to file; only check the formatted result in the `text` output (preview of the conversion)
#### Output
- `text`
- The formatted caption
- `file_path`
- Full path of the save destination (the planned path when `dry_run`)
---
### D2 Tag Report
- A node that aggregates tag frequency from captions in the specified folder and builds an exclude-tag list
- The `Get tags` button shows the aggregated result in `text`. The user edits which tags to keep/remove and passes it to `exclude_tags` of `D2 Save Caption`
- Prefixing a line with `//` or `#` makes it a comment line
- When a tag dictionary is given to `exclude_tags`, only the tags **not listed in the dictionary** are counted
- This surfaces mistyped prompts such as a missing comma (`blue eyes twintails`) or a missing space (`blondehair`)
- For how to use `D2 Tag Report` and `D2 Save Caption`, see this article (Japanese)
- https://note.com/da2el_ai/n/ne1fc9b3bea89?app_launch=false
#### Input
- `folder`
- The folder containing the caption files (full path)
- `include_subfolders`
- `true`: Also target subfolders
- `extension`
- Target extension (e.g. `txt`)
- `order_by`
- `count_9-0`: Descending by occurrence count
- `count_0-9`: Ascending by occurrence count
- `tag_a-z`: By tag name (A->Z)
- `tag_z-a`: By tag name (Z->A)
- `without_count`
- `true`: Do not show occurrence counts in the report
- `exclude_tags`
- The file path of the tag dictionary to exclude from counting (full path)
- Note that you specify the path of the dictionary file, not its contents
- `output_type`
- `remove_comment`: Remove comment lines and output the rest (workflow: mark tags to remove with comments)
- `output_comment`: Output only comment lines (workflow: comment out only the tags to remove)
- `separator`
- `newline`: Output line-separated (recommended, so entries containing commas such as `regex/pattern/` are not broken)
- `comma`: Output as a single line separated by comma + space
#### Output
- `text`
- The edited tag list (passed to `exclude_tags` of `D2 Save Caption`)
#### About exclude_tags
- A feature for surfacing **tags that are likely mistyped**, that is, tags not listed in the dictionary
- Tags listed in the dictionary are not counted, so only tags missing from the dictionary remain in the report
- Three dictionary formats are supported. In all of them the first column is read as the tag
- A plain list of tags
```csv
1girl
solo
```
- A format without a header row (such as ComfyUI Custom Scripts)
```csv
1girl,4114588
solo,3426446
```
- A format with a header row (such as ComfyUI Auto Complete Plus)
```csv
tag,category,count,alias
1girl,0,4974288,"girl,woman,lady"
```
- Matching ignores letter case, the difference between spaces and underscores (`long hair` and `long_hair`), and bracket escaping (`\(` and `(`)
- **Note**: The `Get tags` button runs before the workflow executes, so a value connected from another node cannot be read. Always type the dictionary path directly into this field