Why and How to Combine Text/Pixel Replacement Variables With Visibility Variables in Photoshop
Data-driven graphics (Variables and Data Sets) is lesser known but very powerful automation feature in Photoshop. So far I have covered most of the options and tips how to use Variables and Data sets. In this post, I will cover why and how to combine text substitution/pixel replacement variables with visibility variables.
Why combine variables?There are many reasons to combine two types of variables which can be assigned to a layer. Here are a couple of reasons to combine text/pixel replacement and visibility variables:
- Using text replacement variables in combination with visibility variables you can control which text is visible per exported file. For example, you have a task to combine images with text in the batch process. With some images, you may need to display only one type layer while other images will require two or more type layers.
- Another example is when you have a task to combine images and text but you want different fonts to use with some of the images.
- The third example is that you need to batch process files with different quotes which need 2 or more different fonts, depend on the quote.
- The fourth example is that you want to use the same layout but a different number of images should be displayed.
- The fifth example is that you want to use the image as a background with text as an overlay but some text requires solid background without an image.
This list can be expanded with more situations when it can be useful to combine text replacement or pixel replacement variables with visibility variables. Let's stop at above examples to proceed with basics which can be useful in real-world projects.
Basics of visibility variablesIf you not familiar with data-driven graphics please read my previous posts to familiarize yourself with this functionality in Photoshop.
Here is how things work in short: you can assign variable to any layer/layer group beside Background layer. Data set contains the name(s) of the variable(s) in the first row and data in each other row. Data can be a path to an image file, text for substitution or true/false. When the name of the variable from the first column in data set and the name of the variable which is assigned in Photoshop to some layer/layer group match, data is passed to layer to substitute pixels, text or to show/hide that layer.
Visibility variable can be assigned to any layer or layer group including nested layer groups. For some type of layers (Adjustment layer, Smart Object layer) that's the only variable that is available to assign.
Visibility variable controls the visibility of layer or layer group. In external data set visibility is controlled using true/false where true means layer is visible while false means layer is hidden. In other words, word false instructs Photoshop to turn off the visibility of that layer.
There is workaround when using Pixel Replacement and Text Replacement variables to make content on layer(s) invisible without assigning visibility variable but let's keep that for later.
Steps to create visibility variableYou must have at least one regular layer in your document (besides Background layer).
- Go to Image > Variables > Define...
- In the Variables dialog use Layer drop-down to choose layer for which you want to assign visibility variable.
- Click on Visibility to appear checkmark. You can use default naming convention or to type variable name in the Name: textbox.
- Click OK button to confirm and exit Variables dialog.
- Save the document as PSD (recommended), PSB or layered TIFF file.
Variables are backward compatible. The current version is CC 2018 and I have tested back to Photoshop CS6. Everything works just fine, document open in CS6 contains information about an assigned variable.
How to combine Visibility variable with Pixel/Text replacement variableIn Photoshop you can assign two (2) variables for pixel based (blank layer, shape layer, layer with pixel fill) and type layers. One variable can be assigned for replacement on the layer and the second variable can be assigned to control the visibility of that layer.
Use Pixel/Text Replacement variable to replace pixels or to substitute existing text on the layer. Use Visibility variable to control the visibility of the layer. Here is how that looks in external data set.
|Pixel replacement and visibility variables combined in external data set created in Notepad++. Comma is used as separator.|
|Pixel replacement and visibility variables combined in external data set created in Google Sheets. File is exported as comma separated .csv file.|
Note: you cannot leave value blank for Pixel/Text Replacement variable in external data set even if you do not want that image/text to appear on the layer. Point to file or type some text then set visibility variable to false.
Now you have a question: why use visibility variables anyway? You could just skip one row or leave the blank field in data set and deed is done! Well, first of all, you cannot leave the blank field in a column with a variable. Second: sometimes you will have a more complicated situation where you need to display image with overlay text while other files need to be exported without background (or any other) image. If you have assigned variable to some layer in Photoshop you must have that variable in data set and to provide data in each row/column in data set.
How to create data sets in Photoshop with visibility variablesThere are two ways to use visibility variables. You can create data sets inside Photoshop or use external data sets saved as .txt or .csv file.
Here are the steps to create data sets inside Photoshop:
- Go to Image Variables > Define.
- Choose layer for which you want to create visibility variable from Layer drop-down list. Click on Visibility to appear checkmark. Optionally retype default name for the variable in the Name: textbox.
- After defining visibility variable click Next button.
- Click Create a new data set based on the current data set to create data set.
- Click on a row with visibility variable to select that row.
- Use Value: radio buttons to set visibility to Visible or Invisible.
- If you want to to use preview while creating data set click on Preview on the right side to appear checkmark so you can see an instant update of changes you are making.
- Create more data sets if you wish and repeat steps by selecting a row with visibility variable(s) and setting visibility options.
- Click OK button to save and exit.
|Steps to assign visibility variable and to create data sets in Photoshop (see detailed description above this animation).|
External data setsYou can use software like MS Excel, Google Sheets or any text editor like Notepad++. The important part is:
- Encoding of the text file. I prefer UTF-8.
- Variable names go in the first row. Variable values go in rows below.
- A number of variables and their names in the external file must match variable number/names created in Photoshop.
- Variable names and their values must be comma or tab separated. Do not press tab or type comma at the end of the line.
- No space is allowed at the beginning or end of row.
- No missing data is allowed. If you have 3 variables in the first row then any other row in that file must have three values either comma or tab separated.
Steps to create external data setsI will use Notepad++ to create external data set. For a larger amount of data, you can use spreadsheet application like Excel or Google Sheets. Here are the steps:
- In the first row type visibility variable(s) name(s). As already mentioned, a number of variables and their names must match number and names of variables created in Photoshop. Separate variables using comma or tab separator.
- In the second row, type values true or false. A number of values must match a number of variables in the first row. Separate values using comma or tab separator.
- In the third and every other row repeat step 2.
- Check encoding before saving file. I prefer UTF-8. Other encodings that can be used: UTF-16, Western (ISO Latin 1), Western (Mac OS Roman), Native (CJK).
- Save the file with .txt extension.
|External data sets created in Notepad++. Tab is used for separator.|
How to load and preview external data setIn Photoshop you must have an open document with variables assigned.
- Go to Image > Variables > Data Sets.
- Click on Import button.
- Click on Select File button and navigate to external data sets.
- Check that encoding is set to Automatic or choose from the drop-down list encoding which you have used when creating data sets.
- Click OK button.
- Ensure that Preview checkbox is turned on.
- Preview data sets using Prev/Next buttons on the right side of Data Set:. Click OK button to confirm and exit.
|Steps to load and preview external data sets in Photoshop|
How to export data setsLet me mention steps to export files with data sets. I will assume that you have assigned variables to layers. I will also assume that you have created/loaded data sets as explained above.
- Go to File > Export > Data Sets as Files...
- Click on Select Folder button and navigate to the folder where you want to save exported PSD files.
- From Data Set drop-down list you can choose All Data Sets or single data set to export.
- Click OK button and wait for Photoshop to finish its job.
Workaround to skip visibility variables with Text/Pixel replacement variablesIf you do not want to use visibility variables with Pixel and Text replacement variables.
To substitute pixels with transparency (same effect as the visibility of layer set to false) do the following:
Save the .psd file with transparent background. Let's name it transparent background.psd.
Use transparent background.psd for Pixel Replacement variable. You will get the same final effect as with visibility of that layer set to true.
To substitute text with transparency (same effect as the visibility of the layer set to false) do the following:
In Data Set file type " " (double quotes, space, double quotes) for text substitution. You will get the same final effect as with visibility of that layer set to true.
All posts in this mini-course
Easy Way to Automate Photoshop with Variables
Easy Way to Automate Photoshop with Variables (Part 2)
Easy Way to Automate Photoshop with Variables (Part 3)
Easy Way to Automate Photoshop with Variables (Part 4)
Easy Way to Automate Photoshop with Variables (Part 5)
Easy Way to Automate Photoshop with Variables (Part 6)
Easy Way to Automate Photoshop with Variables (Part 7)
Why and How to Combine Text/Pixel Replacement Variables With Visibility Variables in Photoshop
Product used in this tutorial:
Adobe Photoshop CC 2018
Create data-driven graphics