Skip to main content
maria0101
Known Participant
October 8, 2018
Answered

Place new guide 1cm from existing guide

  • October 8, 2018
  • 1 reply
  • 821 views

My horizontal guide changes position for every PSD file I use, and I want to use a script to place 3 guides 1cm away from the existing guide I have already placed, so I have 4 guides 1cm apart.

What I'm currently doing is setting my ruler origin to the guide and using an action to place 3 more guides. Sometimes I also need 7 guides, or 9 so this changes as well. I know you can place guides from, say, 500px into the PSD using new guide layout, but I need it from the custom horizontal guide I already have set out. If there was even a script to set the ruler origin to this guide, that would be fine too.

Many thanks in advance!

This topic has been closed for replies.
Correct answer Stephen Marsh

I’m a scripting newb, however it does appear to be possible to find the position of a placed guide, so what you wan’t should be possible, presuming that there is only one guide existing:

How to get exact position of a ruler guide in Photoshop? - Super User

EDIT:

The following is my fledgling start/prototype, presuming only a single guide:

var savedRuler = app.preferences.rulerUnits; //store the current ruler units

app.preferences.rulerUnits = Units.CM; //set the ruler units to CM

var guidePos = app.activeDocument.guides[0] //retrieve the existing guide

activeDocument.guides.add(Direction.HORIZONTAL, guidePos.coordinate.value + 1); //add new guide +1cm from existing guide

activeDocument.guides.add(Direction.HORIZONTAL, guidePos.coordinate.value - 1); //add new guide -1cm from existing guide

app.preferences.rulerUnits = savedRuler //restore the original ruler units

This simple code will add two new horizontal guides, 1cm above and below the existing guide. I’m sure that lines 04 + 05 can be refined into a single line (the syntax currently eludes me).

If you start with a single guide, and add three more, are these simply added at a positive or negative distance from the original, up or down the height of the image?

What you need is a GUI where you can enter in N number of guides, which is beyond my current knowledge and skillset (I was lucky to make it this far). Unfortunately this code is not much better than your current action… However I hope that this helps you to get the ball rolling, I’m looking forward to what the experts come up with!

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
October 8, 2018

I’m a scripting newb, however it does appear to be possible to find the position of a placed guide, so what you wan’t should be possible, presuming that there is only one guide existing:

How to get exact position of a ruler guide in Photoshop? - Super User

EDIT:

The following is my fledgling start/prototype, presuming only a single guide:

var savedRuler = app.preferences.rulerUnits; //store the current ruler units

app.preferences.rulerUnits = Units.CM; //set the ruler units to CM

var guidePos = app.activeDocument.guides[0] //retrieve the existing guide

activeDocument.guides.add(Direction.HORIZONTAL, guidePos.coordinate.value + 1); //add new guide +1cm from existing guide

activeDocument.guides.add(Direction.HORIZONTAL, guidePos.coordinate.value - 1); //add new guide -1cm from existing guide

app.preferences.rulerUnits = savedRuler //restore the original ruler units

This simple code will add two new horizontal guides, 1cm above and below the existing guide. I’m sure that lines 04 + 05 can be refined into a single line (the syntax currently eludes me).

If you start with a single guide, and add three more, are these simply added at a positive or negative distance from the original, up or down the height of the image?

What you need is a GUI where you can enter in N number of guides, which is beyond my current knowledge and skillset (I was lucky to make it this far). Unfortunately this code is not much better than your current action… However I hope that this helps you to get the ball rolling, I’m looking forward to what the experts come up with!

maria0101
maria0101Author
Known Participant
October 9, 2018

Thank you so much!! This is exactly what I was after. At the moment, I'll make multiple copies and each one will have a different line for the amount of rulers needed. Then I'll update my actions with these new scripts. It seems ok at the moment to select from the list of actions how many I need. At least this way is still faster than the way I was doing it before. Thanks again!