ComfyUI wildcards in prompt using Text Load Line From File node

How to use the Text Load Line From File node from WAS Node Suite to dynamically load wildcards line by line from external text files into your ComfyUI prompt.

Requirements

  • ComfyUI Manager: Recommended to manage plugins.
  • ComfyUI Custom Scripts : Provides the Show Text 🐍 node.
  • WAS Node Suite : Provides the Logic Boolean, Number Counter, Text Load Line From File, Text Concatenate nodes.
  • Rgthree: Provides the Power Lora Loader node (optional)
  • Text file with one (or more) wildcard words per line.

Whenever this workflow is run, the generated prompt will include a line of text from your wildcard file anywhere in the prompt, by retrieving a line of text with the Text Load Line From File in combination with the Number Counter and Text Find and Replace node.

Load Wildcard From File Sdxl

Load Wildcard From File Sdxl

Load wildcard nodes group explained

To begin, your wildcard text file should be placed in your ComfyUI/input folder. You can download wildcard files from CivitAI, Hugging Face, or create your own, since they are regular plain text files that can be created with Notepad.

Logic Boolean node

Setting boolean to 1.00 means that the workflow will load the first line of the text file everytime it’s executed. Set it to 0.00 for normal operation!
Logic Boolean Node

Logic Boolean Node with reference note

This node is used to restart reading lines from your wildcards text file according to its boolean value (which is technically not a boolean, but an integer).

  • Set boolean to 1 to restart execution from the first line of the wildcard text file (once)
  • Set boolean to 0 to continue from the next line (normal workflow operation)

Number Counter node

Number Counter Node

Number Counter Node

Determines which line number to read from your wildcard file. You must connect its int output to the index input from the Text Load Line From File node.

  • Set start to the first line number to read from the wildcard file, please note this may or may not work, recommended value is 0 (start from first line).
  • Set stop to the last line you want to read from the wildcard file. Should match the total number of lines from your text file.
  • Set step to 1.00 to increase the counter by 1 each time the prompt is run.

Text Load Line From File node

For technical reasons too complex to deal with, the sample workflow will always skip the first line from the wildcard file
Text Load Line From File Node

Text Load Line From File Node

Reads a line from the prompts text file, configuration is as follows:

  1. First, convert the node’s index widget value to input by right-clicking on it and selecting Convert Widget to Input > Convert index to input.
  2. Set the file_path to the full wildcards TXT file path and name.
  3. Set mode to index.

Show Text 🐍 nodes

The Show Text node on the left will simply show the current line number, the node on the right will preview the final prompt generated in the current iteration. These are optional nodes.

Text Multiline node

Text Multiline Node

Text Multiline Node

Sets your full prompt. Must include the @wildcard placeholder, that will be replaced with a line from the wildcard file on each run. In this case, the wildcard word has its weight slightly increased (1.1) to make sure it’s not ignored by the sampler.

You may replace @wildcard with any unique keyword, such as #wildcard, $wildcard, etc. It’s a programming convention to use a special character to indicate this string represents a variable value.

Text Find and replace node

Text Find And Replace Node

Text Find And Replace Node

Given a text input (your full prompt), it will replace the value defined by the find widget (in this case, “@wildcard”) and replace it with the replace input value (a full line from our wildcard file).

The result_text output will contain the full prompt with the wildcard from the text file. Connect this output to your Clip Text Encode (Prompt) text input value. The rest of your workdlow continues as usual.

The sample Save Image node uses the filename_prefix %date:yyyy-MM-dd%/%date:hhmmss% to save the images on a folder with current date.

Demo workflow samples

Our Costumes.txt file generated a batch of more than 180 costumes for our Kagome subject, and the LoRA’s trained clothing was replaced with the costumes from our file.

🔻Download JSON workflow

Notice: An earlier version of this workflow used the Text Concatenate node, which resulted in extra nodes. This is a simplified version with the less clutter, and optimized for SDXL models.

Disclaimer

The content in this post is for general information purposes only. The information is provided by the author and/or external sources and while we endeavour to keep the information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services, or related graphics contained on the post for any purpose. Some of the content and images used in this post may be copyrighted by their respective owners. The use of such materials is intended to be for educational and informational purposes only, and is not intended to infringe on the copyrights of any individuals or entities. If you believe that any content or images used here violate your copyright, please contact us and we will take appropriate measures to remove or attribute the material in question.