Fill guides with path - lines - Line Tool (Paths)

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Gewuerz

Fill guides with path - lines - Line Tool (Paths)

Post by Gewuerz »

Hello

I made often any guides with the helpful GuideGuide Panel from Cameron McEffee. Thanks for this tool!
On this guides along, i make (path) lines by hand now (at the moment) with the "Line Tool". I think this would be faster with a script..
But I do not know how?
So, all guides should get a (shape) line with the Shapetool "Line Tool" in maximal the documents bounds, automatically.
If that would be possible with a add menu for user-selectable parameters: width (thickness), color, for the lines?

Thanks for help Wolfgang

Photoshop CS 6
Win 7 64bit


I would donate something for the forum for a solution.

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Fill guides with path - lines - Line Tool (Paths)

Post by Mike Hale »

A screenshot of what you want done may help. I am not clear about where the paths are drawn.
Paul MR

Fill guides with path - lines - Line Tool (Paths)

Post by Paul MR »

Is this what you are wanting? ...

Code: Select all#target photoshop
app.bringToFront();

main();
function main(){
if(app.version.match(/\d+/) < 12){
    alert("You need Photoshop CS5 or better to use this script");
    return;
    }
if(!documents.length) return;
var guides = app.activeDocument.guides;
if(guides.length == 0){
    alert("There are no guides to process!");
    return;
}
var win = new Window( 'dialog', '' );
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
win.orientation='stack';
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Create ShapePaths');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.g5 =win.p1.add('group');
win.g5.orientation = "row";
win.g5.alignment='fill';
win.g5.spacing=10;
win.g5.st1 = win.g5.add('statictext',undefined,'Use Foreground Colour');
win.g5.p1 = win.g5.add("panel", undefined, undefined, {borderStyle:"black"});
win.g5.p1.preferredSize=[50,20];
win.g5.bu1 = win.g5.add('button',undefined,'Or Select Colour');
panelColour=app.foregroundColor;
function setPanel(pColour){
panelColour=pColour;
var r = pColour.rgb.red/255;
var g = pColour.rgb.green/255;
var b = pColour.rgb.blue/255;
var C = win.g5.p1.graphics;
myBrush = C.newBrush(C.BrushType.SOLID_COLOR, [r, g, b, 1]);
C.backgroundColor = myBrush;
}
setPanel(app.foregroundColor);
win.g5.bu1.onClick=function(){
var sColour = getColour();
setPanel(sColour);
}
win.g10 =win.p1.add('group');
win.g10.orientation = "row";
win.g10.alignment='fill';
win.g10.spacing=10;
win.g10.st1 = win.g10.add('statictext',undefined,'Set Width');
win.g10.et1 = win.g10.add('edittext',undefined,'1');
win.g10.et1.preferredSize=[50,20];
win.g10.et1.onChanging = function() {
  if (this.text.match(/[^\-\.\d]/)) {
    this.text = this.text.replace(/[^\-\.\d]/g, '');
  }
};
win.g10.cb1 = win.g10.add('checkbox',undefined,'Clear Guides?');
win.g15 =win.p1.add('group');
win.g15.orientation = "row";
win.g15.alignment='center';
win.g15.spacing=10;
win.g15.bu1 = win.g15.add('button',undefined,'Process');
win.g15.bu1.preferredSize=[150,35];
win.g15.bu2 = win.g15.add('button',undefined,'Cancel');
win.g15.bu2.preferredSize=[150,35];
win.g15.bu1.onClick=function(){
if(win.g10.et1.text == ''){
    alert("No width has been entered");
    return;
    }
win.close(0);
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
guides = app.activeDocument.guides;
for( var g =0; g<guides.length;g++ ){
    if(guides[g].direction.toString() == 'Direction.HORIZONTAL'){
        createLinePath(false,parseInt(guides[g].coordinate.value),Number(win.g10.et1.text));
        }else{
            createLinePath(true , parseInt(guides[g].coordinate.value),Number(win.g10.et1.text));
            }
        createShape(panelColour);
}
if(win.g10.cb1.value) clearGuides();
preferences.rulerUnits = startRulerUnits;
}
win.center();
win.show();
}
function getColour(){
var originalColour = app.foregroundColor;
app.showColorPicker();
var selectedColour = app.foregroundColor;
app.foregroundColor = originalColour;
return selectedColour;
}
function createLinePath(Vert,gPix,W) {
var doc = activeDocument;
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID('Path'), charIDToTypeID('WrPt') );
desc.putReference( charIDToTypeID('null'), ref );
var desc2 = new ActionDescriptor();
var desc3 = new ActionDescriptor();
var desc4 = new ActionDescriptor();
if(!Vert){
desc3.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
desc3.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), gPix );
desc4.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), doc.width.as('px') );
desc4.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), gPix );
}else{
desc3.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), gPix );
desc3.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
desc4.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), gPix );
desc4.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), doc.height.as('px') );
    }
desc2.putObject( charIDToTypeID('Strt'), charIDToTypeID('Pnt '), desc3 );
desc2.putObject( charIDToTypeID('End '), charIDToTypeID('Pnt '), desc4 );
desc2.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Pxl'), W );
desc.putObject( charIDToTypeID('T   '), charIDToTypeID('Ln  '), desc2 );
executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
};
function createShape(selectedColour) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( stringIDToTypeID('contentLayer') );
desc .putReference( charIDToTypeID('null'), ref );
var desc2  = new ActionDescriptor();
desc2 .putBoolean( charIDToTypeID('Grup'), true );
var desc3  = new ActionDescriptor();
var desc4 = new ActionDescriptor();
desc4.putDouble( charIDToTypeID('Rd  '), selectedColour.rgb.red );
desc4.putDouble( charIDToTypeID('Grn '), selectedColour.rgb.green );
desc4.putDouble( charIDToTypeID('Bl  '), selectedColour.rgb.blue );
desc3 .putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), desc4 );
desc2 .putObject( charIDToTypeID('Type'), stringIDToTypeID('solidColorLayer'), desc3  );
desc .putObject( charIDToTypeID('Usng'), stringIDToTypeID('contentLayer'), desc2  );
executeAction( charIDToTypeID('Mk  '), desc , DialogModes.NO );
};
function clearGuides() {
var id556 = charIDToTypeID( "Dlt " );
var desc = new ActionDescriptor();
var id557 = charIDToTypeID( "null" );
var ref = new ActionReference();
var id558 = charIDToTypeID( "Gd  " );
var id559 = charIDToTypeID( "Ordn" );
var id560 = charIDToTypeID( "Al  " );
ref.putEnumerated( id558, id559, id560 );
desc.putReference( id557, ref );
executeAction( id556, desc, DialogModes.NO );
};


Gewuerz

Fill guides with path - lines - Line Tool (Paths)

Post by Gewuerz »

Thanks Paul,

Whit the script in your post, noting happening when I click on it.
I mean like in the attached .zip file. Guides2PathLines-Screen.zip (148.18 KiB) Downloaded 65 times

Thanks Wolfgang
Paul MR

Fill guides with path - lines - Line Tool (Paths)

Post by Paul MR »

Hi Wolfgang, ths is what happens on my system...
http://youtu.be/FUZEd4GqnYQ


I wonder if you have tried running the code from ExtendScript Toolkit? If so does it show any errors?
Could it be because of the different language?
Gewuerz

Fill guides with path - lines - Line Tool (Paths)

Post by Gewuerz »

Hi Paul,.

This pathShape Script works fine! Great thanks!

What needs to change in the script, all these line path layers in a layer-group are summarized at the end?

Thanks and best greetings Wolfgang
Paul MR

Fill guides with path - lines - Line Tool (Paths)

Post by Paul MR »

This version will put them into layersets...
Gewuerz

Fill guides with path - lines - Line Tool (Paths)

Post by Gewuerz »

Great thanks Paul, very helpful! I have now donated for the super PS-Scripts forum.

One more question: Can you convert also simple the guides , only in individual paths (work paths) with a script?
And then i can stroke path with brushes, for example.

Thanks and best greetings Wolfgang
Paul MR

Fill guides with path - lines - Line Tool (Paths)

Post by Paul MR »

This will create paths named "Guide 1" etc..
Gewuerz

Fill guides with path - lines - Line Tool (Paths)

Post by Gewuerz »

Wow Paul,

thanks, this will help for any works.

Thanks and best greetings Wolfgang