-
-
Notifications
You must be signed in to change notification settings - Fork 562
XYZ Grid
The X/Y/Z Grid script generates multiple images while automatically varying selected values, then displays results in labeled grids.
To activate X/Y/Z Grid, open the Script dropdown and select "X/Y/Z Grid".
Several new UI controls will appear.
X, Y, and Z Types define what changes across generated images.
X Type creates columns, Y Type creates rows, and Z Type creates separate grid images (a "3D grid" effect). X/Y/Z Values define the actual values to test. For some types, values are selected from a dropdown. For others, values are comma-separated.
Most options are self-explanatory, such as Model, Seed, VAE, and CLiP Skip.
"Prompt S/R" means Prompt Search and Replace. After selecting this type, enter a word already present in your prompt, followed by comma-separated replacements.
For example, if your prompt is "a lazy cat" and Prompt S/R is cat,dog,monkey, the script creates three images:
a lazy cat, a lazy dog, and a lazy monkey.
You are not limited to single words. You can replace phrases, for example lazy cat,boisterous dog,mischievous monkey, or even the full prompt, for example a lazy cat,three blind mice,an astronaut on the moon.
Embeddings and LoRAs are also valid search-and-replace terms, for example <lora:FirstLora:1>,<lora:SecondLora:1>,<lora:ThirdLora:1>.
You could also change the strength of a lora; <lora:FirstLora:1>,<lora:FirstLora:0.75>,<lora:FirstLora:0.5>,<lora:FirstLora:0.25>.
(Note: You could strip this down to FirstLora:1,FirstLora:0.75,FirstLora:0.5,FirstLora:0.25.)
Replacement values are separated by commas, so every comma in the field is treated as a separator. Quotation marks are not special and do not group a value; wrapping a replacement in "..." only adds literal quote characters to the prompt.
A comma that belongs inside a single replacement is escaped with a backslash, written as \,. The backslash is stripped before the prompt is used, leaving an ordinary comma. This matters most when the whole prompt is replaced with alternatives that themselves contain commas.
For example, the prompt is a lazy cat and the goal is to swap the whole prompt for two alternatives that contain commas.
Without escaping, the value a lazy cat,a happy dog, wearing a hat,a wise owl, perched on a branch is split on every comma into five values: a lazy cat, a happy dog, wearing a hat, a wise owl, and perched on a branch. The result is five images with broken prompts.
With escaping, the value a lazy cat,a happy dog\, wearing a hat,a wise owl\, perched on a branch is split into three values. Because the search term a lazy cat is the full prompt, each value becomes a complete prompt, producing the three intended images: a lazy cat, a happy dog, wearing a hat, and a wise owl, perched on a branch.
Search and replace acts on every value in the field, and each is a plain text replacement with no word boundaries. A term is replaced wherever it occurs, including inside longer words. With the prompt a cat, intricate details and Prompt S/R cat,dog,owl, the cat inside intricate is replaced along with the standalone word: the second image becomes a dog, intridoge details and the third becomes a owl, intriowle details.
Distinctive terms avoid this. With Prompt S/R a cat,a fox,a wolf, none of the values occur inside intricate, so only the subject changes, giving a cat, intricate details, a fox, intricate details, and a wolf, intricate details.
A placeholder token marks a fixed insertion point in the prompt and can be reused to fill several positions from a single value. The token works best when it is distinctive, so it does not match inside other words, and it avoids the __name__ form, which is reserved for wildcards.
For a fixed insertion point, the prompt portrait of SUBJECT_SLOT, oil painting, golden hour with Prompt S/R SUBJECT_SLOT,a fox,a deer,an owl varies only the subject while the style and lighting stay constant, giving portrait of a fox, oil painting, golden hour, portrait of a deer, oil painting, golden hour, and portrait of an owl, oil painting, golden hour.
For repeated positions, a token is replaced everywhere it appears. The prompt COLOR_SLOT hair and COLOR_SLOT eyes with Prompt S/R COLOR_SLOT,red,blue,green fills both positions from one value, giving red hair and red eyes, blue hair and blue eyes, and green hair and green eyes.
A placeholder also replaces the whole prompt with unrelated alternatives. The prompt PROMPT with Prompt S/R PROMPT,a serene lake at dawn\, misty,a neon cyberpunk alley\, raining produces three images:
-
PROMPT(the first value is the search term, so the first cell renders the literal token unchanged) a serene lake at dawn, mistya neon cyberpunk alley, raining
Each replacement is a complete prompt on its own: the token is not repeated in front of it, and internal commas are escaped as \,. When a usable first image matters more than a comma-free anchor, a complete prompt is placed in the prompt box and used as the first value instead of a token.