Skip to content

Instantly share code, notes, and snippets.

@D4R4
Created October 28, 2019 09:18
Show Gist options
  • Save D4R4/a57b217a19b46c482bd08a71b8f94f76 to your computer and use it in GitHub Desktop.
Save D4R4/a57b217a19b46c482bd08a71b8f94f76 to your computer and use it in GitHub Desktop.
Script to convert all guides to strokes with specific color and stroke size in Photoshop
//Requires Photoshop CS5 or newer
#target photoshop;
if(documents.length) app.activeDocument.suspendHistory('Stroke Guides', 'main()');
function main(){
activeDocument.artLayers.add();
activeDocument.activeLayer.name="Stroked Guides";
app.showColorPicker();
var newColour = app.foregroundColor;
var guideSize = Window.prompt("Please enter Stroke Size!","1");
var guides = app.activeDocument.guides;
var guideArray = [];
for( var g = 0; g < guides.length; g++ ){
singleLine(guides.direction.toString(), Number(guides.coordinate.value).toFixed(0) );
if(Number(guideSize) > 1)
activeDocument.selection.stroke (newColour, Number(guideSize), StrokeLocation.OUTSIDE, ColorBlendMode.NORMAL, 100, false);
activeDocument.selection.stroke (newColour, Number(guideSize), StrokeLocation.INSIDE, ColorBlendMode.NORMAL, 100, false);
}
activeDocument.selection.deselect();
};
function singleLine(pos,pixelPos) {
var desc5 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') );
desc5.putReference( charIDToTypeID('null'), ref4 );
var desc6 = new ActionDescriptor();
if(pos == "Direction.VERTICAL"){
desc6.putUnitDouble( charIDToTypeID('Left'), charIDToTypeID('#Pxl'), Number(pixelPos) );
desc5.putObject( charIDToTypeID('T '), charIDToTypeID('Sngc'), desc6 );
}else{
desc6.putUnitDouble( charIDToTypeID('Top '), charIDToTypeID('#Pxl'), Number(pixelPos) );
desc5.putObject( charIDToTypeID('T '), charIDToTypeID('Sngr'), desc6 );
}
executeAction( charIDToTypeID('setd'), desc5, DialogModes.NO );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment