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 a pre-made 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 used in this workflow.
  • Text file with one (or more) wildcard words per line.

Workflow explained

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 node, and concatenating it with the rest of the prompt using the Text Concatenate node.

ComfyUi sample workflow Load Wildcards In Prompt

ComfyUi sample workflow Load Wildcards In Prompt

Load Wildcard node group explained

Load Wildcards In Prompt Group

Load Wildcard from File group. The optional green nodes are for preview only and can be skipped.

  1. Your wildcard text file should be placed in your ComfyUI/input folder
  2. Logic Boolean node: Used to restart reading lines from text file.
    1. Set boolean_number to 1 to restart from the first line of the wildcard text file.
    2. Set boolean_number to 0 to continue from the next line.
  3. Number Counter node: Used to increment the index from the Text Load Line From File node, so it reads the next line each time the prompt is queued.
    1. Set start to the first line you want to read from the prompt file.
    2. Set stop to the last line you want to read from the prompt file.
    3. Set step to 1.00 to increase the counter by 1 each time the propmt is run.
  4. Text Load Line From File: used to read a line from the prompts text file.
    1. Convert the node’s index value to input.
    2. Set the file_path to the full prompt file path and name.
    3. Set mode to index.
  5. Primary Show Text 🐍 node: Used to preview the last loaded prompt. Every time the prompt is queued, this will show the next loaded line from your prompts text file.
  6. Secondary Show Text 🐍 node: Used to display the next line number that will be loaded from the prompt text file on the next prompt queue.
  7. Text Concatenate node: Used to merge the wildcard anywhere in your prompt:
    1. text_a: Connect to a Text Multiline node to set the start of the prompt.
    2. text_b: Connect to a Text Load Line From File to insert the wildcard word.
    3. text_c: Connect to a Text Multiline node to set the rest of the prompt.
    4. The resulting prompt will be formed by text_a + text_b + text_c, where text_b is read from the wildcard text file, incrementing the line number every time the promp is queued / run.
  8. Clip Text Encode: This node had its text converted to input in order to connect it to the STRING output of the Text Concatenate node.

Once you have connected the Text Concatenate node STRING output into the Clip Text Encode node’s text input, the rest of the workflow will continue as usual.

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

You can download wildcard files from CivitAI or Hugging Face.

Feedback

If you need help with this workflow, kindly leave a comment using the Disqus Comments section below.

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.