Can You Copy Guides in Photoshop? Streamlining Your Workflow

Copying guides between Photoshop documents can significantly speed up your workflow, ensuring consistency across multiple projects. While Photoshop doesn’t have a built-in function for this, there are effective workarounds using scripts. This article explores how you can copy guides in Photoshop, providing detailed scripts and instructions.

Why Copy Guides in Photoshop?

Guides are essential for precise alignment and layout in Photoshop. Imagine creating a grid system or aligning elements across multiple documents. Manually recreating guides in each document is time-consuming and prone to errors. Copying guides allows you to:

  • Maintain consistency: Ensure elements align perfectly across different files.
  • Save time: Avoid the repetitive task of manually creating guides.
  • Improve accuracy: Reduce the risk of misalignment due to manual placement.

Method 1: Using Photoshop Scripts

The most reliable method to copy guides in Photoshop involves using custom scripts. These scripts automate the process, allowing you to copy and paste guides with ease. Here are three script options:

Option 1: Copy and Paste (Two Separate Scripts)

This method uses two separate scripts – one for copying and one for pasting.

Copy Script:

/* https://www.reflections-ibs.com/blog/articles/how-to-copy-guides-from-one-photoshop-document-to-another https://www.reflections-ibs.com/media/1241/guides-copy.jsx */
#target photoshop
main();

function main(){
  if(Number(app.version.match(/d+/)) <12) return;
  if(!documents.length) return;

  var startRulerUnits = app.preferences.rulerUnits;
  app.preferences.rulerUnits = Units.PIXELS;

  setGuides();

  app.preferences.rulerUnits = startRulerUnits;

  function setGuides(){
    var guides = app.activeDocument.guides;
    if(guides.length == 0){
      alert("No guides exist");
      return;
    }

    var gH = '';
    var gV = '';

    for( var g = 0; g < guides.length; g++ ){
      if(guides[g].direction.toString() == 'Direction.HORIZONTAL'){
        gH+=(parseInt(guides[g].coordinate.value));
        gH+=',';
      }else{
        gV+=(parseInt(guides[g].coordinate.value));
        gV+=','
      }
    }

    gH=gH.replace(/,$/,'');
    gV=gV.replace(/,$/,'');
    currentGuides = 'Layer Guides' + "�" + gH + "�" + gV;

    var desc2 = new ActionDescriptor();
    desc2.putString(0, currentGuides.toSource());
    app.putCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66', desc2, true );
  }

  function displayGuides(){
    try{
      var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
      var layerGuides = eval(desc1.getString(0));
    }catch(e){return;}

    clearGuides();

    var ar1 = layerGuides.toString().split('�');
    var Hor = ar1[1].toString().split(',');
    var Ver = ar1[2].toString().split(',');

    for(var H in Hor){
      activeDocument.guides.add(Direction.HORIZONTAL,new UnitValue(Number(Hor[H]),'px'));
    }
    for(var V in Ver){
      activeDocument.guides.add(Direction.VERTICAL,new UnitValue(Number(Ver[V]),'px'));
    }
  }
}

function clearGuides() {
  var id556 = charIDToTypeID( "Dlt " );
  var desc102 = new ActionDescriptor();
  var id557 = charIDToTypeID( "null" );
  var ref70 = new ActionReference();
  var id558 = charIDToTypeID( "Gd " );
  var id559 = charIDToTypeID( "Ordn" );
  var id560 = charIDToTypeID( "Al " );
  ref70.putEnumerated( id558, id559, id560 );
  desc102.putReference( id557, ref70 );
  executeAction( id556, desc102, DialogModes.NO );
};

Paste Script:

/* https://www.reflections-ibs.com/blog/articles/how-to-copy-guides-from-one-photoshop-document-to-another https://www.reflections-ibs.com/media/1242/guides-paste.jsx */
#target photoshop
main();

function main(){
  if(Number(app.version.match(/d+/)) <12) return;
  if(!documents.length) return;

  var startRulerUnits = app.preferences.rulerUnits;
  app.preferences.rulerUnits = Units.PIXELS;

  displayGuides();

  app.preferences.rulerUnits = startRulerUnits;

  function setGuides(){
    var guides = app.activeDocument.guides;
    if(guides.length == 0){
      alert("No guides exist");
      return;
    }

    var gH = '';
    var gV = '';

    for( var g = 0; g < guides.length; g++ ){
      if(guides[g].direction.toString() == 'Direction.HORIZONTAL'){
        gH+=(parseInt(guides[g].coordinate.value));
        gH+=',';
      }else{
        gV+=(parseInt(guides[g].coordinate.value));
        gV+=','
      }
    }

    gH=gH.replace(/,$/,'');
    gV=gV.replace(/,$/,'');
    currentGuides = 'Layer Guides' + "�" + gH + "�" + gV;

    var desc2 = new ActionDescriptor();
    desc2.putString(0, currentGuides.toSource());
    app.putCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66', desc2, true );
  }

  function displayGuides(){
    try{
      var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
      var layerGuides = eval(desc1.getString(0));
    }catch(e){return;}

    clearGuides();

    var ar1 = layerGuides.toString().split('�');
    var Hor = ar1[1].toString().split(',');
    var Ver = ar1[2].toString().split(',');

    for(var H in Hor){
      activeDocument.guides.add(Direction.HORIZONTAL,new UnitValue(Number(Hor[H]),'px'));
    }
    for(var V in Ver){
      activeDocument.guides.add(Direction.VERTICAL,new UnitValue(Number(Ver[V]),'px'));
    }
  }
}

function clearGuides() {
  var id556 = charIDToTypeID( "Dlt " );
  var desc102 = new ActionDescriptor();
  var id557 = charIDToTypeID( "null" );
  var ref70 = new ActionReference();
  var id558 = charIDToTypeID( "Gd " );
  var id559 = charIDToTypeID( "Ordn" );
  var id560 = charIDToTypeID( "Al " );
  ref70.putEnumerated( id558, id559, id560 );
  desc102.putReference( id557, ref70 );
  executeAction( id556, desc102, DialogModes.NO );
};

Option 2: Combined Copy and Paste Script (Shift Key Modifier)

This script combines the copy and paste functionality into a single script. Holding down the SHIFT key while running the script copies the guides, and running it again in a new document pastes them.

/* https://gist.github.com/codyjlandstrom/5fcb2779b59eb97d862311a2b2815791 https://youtu.be/ERHbxtyOJEg
NOTE: Hold down the shift key when copying guides */
#target photoshop

main();

function main() {
  if (Number(app.version.match(/d+/)) < 12) return;
  if (!documents.length) return;

  var startRulerUnits = app.preferences.rulerUnits;
  app.preferences.rulerUnits = Units.PIXELS;

  if (ScriptUI.environment.keyboardState.shiftKey) {
    setGuides();
    app.beep();
  } else {
    displayGuides();
  }

  app.preferences.rulerUnits = startRulerUnits;

  function setGuides() {
    var guides = app.activeDocument.guides;
    if (guides.length == 0) {
      alert("No guides exist");
      return;
    }

    var gH = '';
    var gV = '';

    for (var g = 0; g < guides.length; g++) {
      if (guides[g].direction.toString() == 'Direction.HORIZONTAL') {
        gH += (parseInt(guides[g].coordinate.value));
        gH += ',';
      } else {
        gV += (parseInt(guides[g].coordinate.value));
        gV += ','
      }
    }

    gH = gH.replace(/,$/, '');
    gV = gV.replace(/,$/, '');
    currentGuides = 'Layer Guides' + "¬" + gH + "¬" + gV;

    var desc2 = new ActionDescriptor();
    desc2.putString(0, currentGuides.toSource());
    app.putCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66', desc2, true);
  }

  function displayGuides() {
    try {
      var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
      var layerGuides = eval(desc1.getString(0));
    } catch (e) {
      return;
    }

    clearGuides();

    var ar1 = layerGuides.toString().split('¬');
    var Hor = ar1[1].toString().split(',');
    var Ver = ar1[2].toString().split(',');

    for (var H in Hor) {
      activeDocument.guides.add(Direction.HORIZONTAL, new UnitValue(Number(Hor[H]), 'px'));
    }
    for (var V in Ver) {
      activeDocument.guides.add(Direction.VERTICAL, new UnitValue(Number(Ver[V]), 'px'));
    }
  }
}

function clearGuides() {
  var id556 = charIDToTypeID("Dlt ");
  var desc102 = new ActionDescriptor();
  var id557 = charIDToTypeID("null");
  var ref70 = new ActionReference();
  var id558 = charIDToTypeID("Gd ");
  var id559 = charIDToTypeID("Ordn");
  var id560 = charIDToTypeID("Al ");
  ref70.putEnumerated(id558, id559, id560);
  desc102.putReference(id557, ref70);
  executeAction(id556, desc102, DialogModes.NO);
};

How to Install and Use the Scripts

  1. Save the script: Copy the script code and save it as a .jsx file (e.g., copyGuides.jsx, pasteGuides.jsx, or combinedGuides.jsx).
  2. Install the script:
    • Open Photoshop.
    • Go to File > Scripts > Browse.
    • Locate and select the .jsx file you saved.

Now, the script will run. For the combined script, remember to hold down the SHIFT key when copying.

Alt text: The scripting interface in Photoshop.

Step-by-Step Instructions

Let’s break down the process of using these scripts to copy guides in Photoshop:

  1. Open the source document: Open the Photoshop document containing the guides you want to copy.
  2. Run the copy script: If using separate scripts, go to File > Scripts and select your copy script. For the combined script, hold down SHIFT and run the script.
  3. Open the destination document: Open the Photoshop document where you want to paste the guides.
  4. Run the paste script: If using separate scripts, go to File > Scripts and select your paste script. For the combined script, run the script without holding down SHIFT.

The guides should now be copied to the destination document.

Alt text: A photoshop document with horizontal and vertical guides.

Troubleshooting

If you encounter issues, consider the following:

  • Photoshop version: Ensure the script is compatible with your Photoshop version (ideally CS6 or newer).
  • Units: The script works with pixels. Make sure your ruler units are set to pixels (View > Rulers, then right-click on the ruler and select “Pixels”).
  • Script errors: Check the Photoshop console for any error messages. Correct any syntax errors in the script.

Alternatives to Scripts

While scripts are the most efficient way to copy guides in Photoshop, here are a couple of alternative methods:

  1. Creating a Template: Save a document with your desired guides as a template. When you need the guides, simply create a new document from the template.
  2. Manual Recreation (Not Recommended): Manually recreate the guides in each document. This is time-consuming and error-prone, so it’s best to avoid this method if possible.

Conclusion

The ability to copy guides in Photoshop is a huge time-saver. By utilizing the scripts provided, you can streamline your workflow, maintain consistency, and improve accuracy in your design projects. Whether you choose the separate copy/paste scripts or the combined script, you’ll find this technique invaluable for any Photoshop user. Remember to keep your ruler units set to pixels for accurate guide placement.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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