Photoshop Variables: How to Import External PSD Smartly

Photoshop Variables: How to Import External PSD Smartly?

When working on large projects, with many mock-ups and style-sheets, even the smallest change on a re-occurring component can take quite some time. Going through the many mock-ups and adjusting a color or font on that re-occurring component can be a grueling task. If you have an intern that does those things for you, you are in luck, but what about us freelancers?

Photoshop Variables

Do we just sit there and endure the pain? Well, not anymore! A while back, I discovered a system that enables designers to say goodbye to opening 23 PSD files just to change the header color. Instead, we can work smart, like our counter parts the developers, and import external files with something called – “Variables”.

This allows us to put the re-occurring component into one external file and simply import that file into all of our mock-ups. When a change is required, we can just change it in one place.

What is a Photoshop Variable?

Here is Adobe’s technical explanation for a variable. A variable is basically used to define which elements in a template change. There are three ways to define a variable.

  1. Visibility Variables – Shows or hides the content of a layer.
  2. Pixel Replacement – Variables that replace the pixels in the layer with pixels from another image file.
  3. Text Replacement – Variables that replace a string of text in a type layer.

You can read more about variables here: Photoshop Define Variables

For our needs, we are going to focus solely on Pixel Replacement, since what we want to do is import an external style-sheet into our PSD.

Lets Get Started

Step 1 – Setting up your files

In this step we need to decide which component in our homepage deserves a variable. In most cases, it is better off creating a variable for a component that re-appears in many different mock-ups. These components can be headers, footers, various sidebar widgets, and anything that re-occurs in the project. In our example, we will use the global header.

Welcome

There are usually many different states to a component (for example, most common is logged in / logged out). This being the case, style-sheets are created for the component, illustrating the states. Ideally, we want to import the component’s style-sheet and make it fit seamlessly into the mock-up. This will provide us with one file acting both as a style-sheet, and as an embedded file that will be imported into all the mocks the component appears in.

Component Global Header

I have created a fake style-sheet for the global header called ‘Component_GlobalHeader.psd’. To continue on with the rest of the steps, please download it below.

[tut download=”http://cdn.onextrapixel.com/wp-content/uploads/2010/01/photoshop-variables.zip”]

Step 2 – Setting up grounds

Let’s open our homepage mock-up and create a new layer. We will give it the same name as the style-sheet’s file name, in our case ‘Component_GlobalHeader.psd’. Let’s call this new layer ‘Component_GlobalHeader’. This is the layer we will be importing the external file to.

Setting Up Ground

Step 3 – Creating the variable

Now it’s time to create the variable. We do this by going to image > variables > define. A popup will appear and we are going to edit some of the parameters.

First of all, always double check that the layer is indeed the correct one (the one we just created). You can check that in the ‘Layer’ field. If it is the incorrect layer, it may cause a bit of a mess later on.

Variable Menu

Since we are focusing on importing, we will go straight to the ‘Pixel Replacement’ option. In the ‘Name’ field, enter the same name as the layer and external style-sheet. It is healthy to keep every name the same as this will help with organization in the future.

Creating The Variable

Next, we are going to focus on ‘Method’. We are going to choose a method for scaling the replacement image/file. There are a few options here:

  1. Fit – scales the image so that it fits in the bounding box (which may leave parts of the bounding box empty).
  2. Fill – scales the image so that it fills the bounding box entirely (which may cause the image to extend beyond the bounding box).
  3. As Is – applies no scaling to the image.
  4. Conform – scales the image disproportionally so that it fits in the bounding box.

What we want is ‘As Is‘ since we do not want to manipulate our external style sheet.

Pixel Replacement

The ‘Alignment’ can be left as the default middle, but this is a personal preference as well as a component consideration. I have aligned top-left in the past as well. It really depends on you.

Let’s leave ‘Clip to Bounding Box’ unchecked.

Click Next.

Step 4 – The actual importing

In order to import the file, we need to either choose or create a new ‘Data Set’. Data sets are collections of variables and associated data. You define a data set for each version of the graphic you want to generate. So if you have many different sidebar widgets in your mock-up, all generated from the same external file, you would only need one data set called ‘sidebar_widgets’.

Since we don’t have any previously created data sets, let’s start by creating a new one. To do this, click on the small disk/arrow icon on the left of the trash icon. Now that we have created a new data set, let’s give it a name. Yep, you guessed it. Let’s give it the same name as the variable, layer, and external style-sheet file. As I’ve said before, they should all be the same name.

Data Sets

Do Not Replace

Now that’s done, we can upload the external file. Click on the ‘select file’ button in the ‘Value’ section, and choose ‘Component_GlobalHeader.psd’. Notice that if you have ‘Preview’ checked (on the right, under the apply button), you will see the new style sheet appear on your homepage mock-up. Super important: always remember to click ‘apply’ before clicking on ‘OK’. If you do not do this, all that we have gone through would be lost and you would need to redo everything. So remember CLICK ‘APPLY’, then click ‘OK’.

Select File

We have successfully imported the external style sheet into our homepage mock-up! Yay! But wait! We now have this massive layer, but need only part of it.

Homepage Mockup

Step 5 – Masking

Since we don’t want the whole style-sheet to appear in our mock-up, we can basically mask the part we need and hide the rest. We will do this by creating a new shape layer in the same dimensions as the component we want to show. Now to get the shape layer to mask it, all we need to do is drag the mask onto the component layer. You will now see the whole screen filled by the shape layer since we removed its mask. Delete the un-masked shape.

Masking

Step 6 – Updating

Now that you have an external file, let me show you how this is useful. Let’s say that the red selected state on your global header just isn’t working for you and you’d like to switch it to blue. Simple! Go to your original style-sheet ‘Component_GlobalHeader.psd’ and change the selected color to blue. Save the file and go back to the homepage mock-up. Click on image > apply Data Sets and choose the data set that you would like to update. You will automatically see the change right away.

Updating

Disadvantages

Along with its potential, keep in mind that this is still considered a hack. Until Adobe decides to create a built-in system for importing external PSDs there will never be a foolproof way to do it.

One major disadvantage is that changing a component PSD and saving it will not automatically change it in the mock-ups associated with it. For example, this means that you will always need to ‘apply data sets’, when opening the homepage mock-up. Though this is something I have not tried, this problem might be able to be solved by creating an action of some sort, making the PSD open and automatically ‘apply data sets’.

Another disadvantage is the folder structure. Moving a file into a new folder tends to mess up the configuration thus creating an error when ‘applying data sets’. Since it is random I haven’t found a way to work around it.

With those issues in mind, I still believe that this system saves countless hours of grueling hard labor. You need to know when to use it. Most of the time, it is used only with projects that contain more than 15 to 20 mock-ups.

Conclusion

This example is just the tip of the iceberg. You can see for yourself the amazing potential this system has. Be creative and experiment. Why not try adding sidebar widgets with only one data set?

Yaron Schoen is an experienced designer, art director and digital artist living in Manhattan, New York. Specializing in many different fields of design with a primary interest in Web & Application Design, Yaron is a veteran in the field and has been in the industry for 11 years. Currently, his focus is on freelance work and entrepreneurship.

Comments

    • RasterBoy,
    • January 28, 2010
    / Reply

    Nice article. Thanks for the information.

    • Olisen,
    • January 28, 2010
    / Reply

    Great! I’m sure to try these techniques out. Thanks for sharing! Appreciate it!

    • Skeku,
    • January 28, 2010
    / Reply

    For things like this I recommend use Fireworks. A tool like “Find & Replace” is a great time saving for changing fonts, colours, objects…

    Just and idea. Nice article BTW :)

  1. / Reply

    Is this “trick” just the same as the “Place” function?

    1. / Reply

      Yes it is very similar, but the variables trick is a bit more powerful. You can create multiple layers that use the same data set for example. This is good for side bar widgets, for example.

      • Kostas Di,
      • January 30, 2010
      / Reply

      With “Place” the external file becomes useless and any updates must happen inside the smart object created. This can be memory intensive from time to time and each time you save, the main file has to update too. Although this method has more steps into it, it allows you to work on each component independently and store them as separate files.

  2. / Reply

    Hi Yaron
    Thanks for sharing this with detailed stuff with snapshots.

  3. / Reply

    Thanks for this. I’ve always wanted to check out the variables but never came around to it.

    I’m however running into an issue that I can not solve. Each time I close my document, it loses all of the data sets I created. Is there a place that I can save these and/or stop them from disappearing at the end of every work session?

    • Mark,
    • June 17, 2010
    / Reply

    Thanks for sharing this!
    I’ve made an action in photoshop to apply data sets. From this action i created a droplet (File > Automate > Create Droplet). Now i only have to drag my PSD’s that have to be altered on this droplet, and they are updated in a blink of an eye. It saves a lot of time!

    1. / Reply

      I just added a keyboard shortcut to ‘Apply Data Sets’ just press enter and they all update.

    • Hans,
    • July 2, 2010
    / Reply

    Thanks, this is really usefull. One question: Every time I re-open my photoshop files containing the header which is a variable I need to define the dataset again. Is this just the way it works or am I doing something wrong?

    I also tried to automate the process but the actions done in the dataset are not recorded in my action. Anybody know what that is?

      • Mark,
      • July 4, 2010
      / Reply

      Hans,
      Defining the dataset every time you re-open a Photoshop file isn’t supposed to be needed.
      It seems like you’re missing one of the steps above?

      If everything is set up the right way, you only have to use the ‘image > apply data set…’ option in order to update your PSD containing the header PSD variable if it has been altered.

    • Kevin,
    • August 4, 2010
    / Reply

    Hi Yaron

    Great tutorial – I design many admin areas with frequesnt components so this is proving a real time saver!

    HOWEVER!

    I have the same problem as Hans – if I close a document then re-open, the APPLY DATA SETS links is greyed out and I have to re-define the data set from scratch.

    This happens every time I quit a PSD or Photoshop itself – the documents never seem to remember their data sets once re-opened. And yes, I have made sure I click ‘apply’ before clicking OK!

    Best
    Kevin

  4. / Reply

    I’m not sure this really is all that different to using smart objects, the extra steps appear in different places but they pretty much do the same.

    Place your external file into your mockup and if if needs updating you just right click and replace contents and select the file again.

    I prefer this new variables method because I’m still in CS3 with that lovely “No Linking Layer Masks with Layers Rule” :) But I fear the set up windows are a little baffling for the average Joe in my studio.

    Both are frustrating, since they highlight how close we are to something so useful. Being able to ‘place’ external psd’s within each other and update them all in one go.

    Why they don’t using proper stylesheets ala inDesign/CSS for objects and text as well is baffling.

  5. / Reply

    And another slight negative with this method is that the layers look like regular layers, ideally they should have they’re own little icon, ala smart objects.

  6. / Reply

    I have to agree with Chris Hart….
    When someone else uses my PSD’s, they will never know that I have used this smart technique. I also prefer to use the smart objects technique. You can easily replace the smart object with an updated version.

    But always nice to explore new Photoshop techniques, thanks for bringing this to my attention!

  7. / Reply

    Oh man you guys saved me. This is the tut I have been searching for. I started my search with very little hope, and bam here it is. Thank you so much! I bookmarked your site because it has so much useful information. You guys are awesome, I really appreciate your help! Keep up the good work!

    • Yan Chatel,
    • February 21, 2011
    / Reply

    Hi,
    the data-driven graphics are best used for creating templates. Once you decided wich parts are going to change, then you can create endless number of images based on simple text files. Let’s say for creating a business cards template bank that holds 200 different models, when ordered, the customer choose what template to use and custom logo and information to show in filling an online form, then online form generates the text files to use for that customer’s order and the graphic designer simply import, verify that all is good and finaly proceed to the printing, all of this in less than 20 minutes….

  8. / Reply

    You can write the Action (Image → Apply Data Set…) and add to Script Event Manager (Open Document).
    When document will be open, all layers will UPDATED.

    or you are can install Includes.jsx scripts for Photoshop and use it. You must PLACE .psd document in your psd template and call File → Scripts → Includes

    Download Includes.jsx: http://alexkrivov.com/includes

    1. / Reply

      @Alex: Great script!!!

      May I make a suggestion? Smart Objects can be exported, and by default have a .psb file extension. However, the current version of your “Includes” script looks for .psd files only, so it won’t work if trying to update content based on a placed Smart Object .psb file. The script would be much more robust if you added support for the .psb file format, as well.

      The great thing about your script is that it allows for quick updating of layers, much like with Variables, but using Smart Objects instead—which offer greater layout flexibility. (There’s also no need to define variables and data sets with this method.)

      Again, by adding support for .psb files, the script will be even more powerful. A Smart Object created in one file could be exported into an external library, where it could then be placed into other documents, as needed. Editing the external version of the Smart Object and then running the Includes script in each file where it was placed would allow for quick updating of those files.

      This even works in CS2! Awesome. Thanks for sharing.

      1. / Reply

        Alex:

        I’ve created a crude alteration of your “Includes.jsx” script that adds support for PSB and AI files: http://tinyurl.com/3ugea6z. I’m certain the syntax of this version could be improved.

        I’ve tentatively renamed the script “Update Smart Objects.jsx”, as that seems more descriptive of its function. An interesting note is that this script updates Smart Objects that have been placed from external files, as well as Smart Objects that may have been created within the document—if they’ve been exported and stored within the same folder as the document itself. As you know, the script scans the active Photoshop document for Smart Object layers, then attempts to match the names of those layers to files within the same folder as the document. If it finds such a file, it uses a Smart Objects > Replace Contents command to automatically update the contents of the corresponding layer.

        The key to using this script in a workflow is either to edit Placed files or Smart Objects externally, or to edit them in the document (as Smart Objects) but then use the Smart Objects > Export Contents command (or Save As…) to also save those files externally, for inclusion into other documents within the same project folder.

        1. / Reply

          Excellent work Alex and Doug! I have modified my version to support more image formats (the usual jpg, png, etc). Would you guys mind if I made this available on my site and other places (like CG Hub) with credit and a link to you guys and your sites?

  9. / Reply

    ok

  10. / Reply

    Thank you so much, this great tuto helps me a lot, thank you !

    • Chris,
    • April 3, 2012
    / Reply

    Great tutorial, however I’m having an issue where every time time I apply the new data set it shifts my “placed” artwork down and to the left a few pixels. Any ideas what could cause this?

    Thanks!

  11. / Reply

    fantastic tutorial, thanks for sharing.

    and also, fantastic audience you have, thanks to everybody that posted before me and tried (and even managed) to improve this workflow, you guys rock.

Leave a Reply

Your email address will not be published. Required fields are marked *

Deals

Iconfinder Coupon Code and Review

Iconfinder offers over 1.5 million beautiful icons for creative professionals to use in websites, apps, and printed publications. Whatever your project, you’re sure to find an icon or icon…

WP Engine Coupon

Considered by many to be the best managed hosting for WordPress out there, WP Engine offers superior technology and customer support in order to keep your WordPress sites secure…

InMotion Hosting Coupon Code

InMotion Hosting has been a top rated CNET hosting company for over 14 years so you know you’ll be getting good service and won’t be risking your hosting company…

SiteGround Coupon: 60% OFF

SiteGround offers a number of hosting solutions and services for including shared hosting, cloud hosting, dedicated servers, reseller hosting, enterprise hosting, and WordPress and Joomla specific hosting.