Last active
June 12, 2024 00:17
-
-
Save codyjlandstrom/5fcb2779b59eb97d862311a2b2815791 to your computer and use it in GitHub Desktop.
Script to copy and paste guides in Photoshop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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(); | |
| }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(1, 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(1)); | |
| }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 ); | |
| }; |
r-bin @ the Adobe forums has fixed the issue for 2024:
Changing the value from 0 to 1:
desc2.putString(1, currentGuides.toSource());
var layerGuides = eval(desc1.getString(1));
Author
Thanks for posting the fix! I'll update the guide
Thanks for posting the fix! I'll update the guide
@codyjlandstrom – please check the Adobe forum link and test, I think that somebody reported unexpected behaviour with the code change. Action Manager isn't easy for me, so I hope that you can work out what's going on in later versions of Photoshop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More here:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/copy-and-paste-guides-photoshop-2024/td-p/14592017