Copy link to clipboard
Copied
Hello,
I need to place one simple vertical guide between the highest points of my image but automatically? Is there any trick for that? The size of the image will be always different but it will always have two highest points.
var old_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var x0 = app.activeDocument.activeLayer.bounds[0].value;
var x1 = app.activeDocument.activeLayer.bounds[2].value;
var y0 = app.activeDoc
Copy link to clipboard
Copied
Script idea...
- make a selection of your object
- convert selection to a path
- compare y-values of the anchor points to find top most anchor point (lowest value).
- place vertical guide to x-value of top most anchor point
Copy link to clipboard
Copied
I get it but I have no idea how to make a script. (no experience with java)
Copy link to clipboard
Copied
var old_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var x0 = app.activeDocument.activeLayer.bounds[0].value;
var x1 = app.activeDocument.activeLayer.bounds[2].value;
var y0 = app.activeDocument.activeLayer.bounds[1].value;
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("transparencyEnum"));
d.putReference(stringIDToTypeID("to"), r1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
app.activeDocument.selection.select([[x0,y0], [x1,y0], [x1,y0+1], [x0,y0+1]], SelectionType.INTERSECT);
app.activeDocument.guides.add(Direction.VERTICAL, (app.activeDocument.selection.bounds[0]+app.activeDocument.selection.bounds[2])/2, SelectionType.INTERSECT);
app.activeDocument.selection.deselect();
app.preferences.rulerUnits = old_units;
Copy link to clipboard
Copied
Oh my. Thats great, it is actually working. Just one thing, I found out that if there are multiple highest points in the same row, the guide will show itself right in the middle of the first and last one.
Would it be possible to edit that script so it would "subtract one half of the path created by the highest points so the guide moves itself to the first highest point?" - attached pic below, I need to get the guide where the black arrow points.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Third line from the end? You mean the word "intersect"? Sorry I just dont know java coding or what kind of words should I replace.
Copy link to clipboard
Copied
Well.
Try replace
(app.activeDocument.selection.bounds[0]+app.activeDocument.selection.bounds[2])/2
with
app.activeDocument.selection.bounds[0]
Helped?
P.S.
Copy link to clipboard
Copied
You are my hero. Thanks.
Copy link to clipboard
Copied
Paranoic, I think it is about time that you familiarise yourself with Photoshop Scripting some more.
Copy link to clipboard
Copied
I know but I dont have time for such learning. I would rather pay a professional who would made me some individual scripts because there is much more I need 😕
Copy link to clipboard
Copied
var old_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("transparencyEnum"));
d.putReference(stringIDToTypeID("to"), r1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
app.activeDocument.quickMaskMode = true;
var d = new ActionDescriptor();
d.putInteger(stringIDToTypeID("level"), 128);
executeAction(stringIDToTypeID("thresholdClassEvent"), d, DialogModes.NO);
app.activeDocument.quickMaskMode = false;
var x0 = app.activeDocument.selection.bounds[0].value;
var x1 = app.activeDocument.selection.bounds[2].value;
var y0 = app.activeDocument.selection.bounds[1].value;
app.activeDocument.selection.select([[x0,y0], [x1,y0], [x1,y0+1], [x0,y0+1]], SelectionType.INTERSECT);
app.activeDocument.guides.add(Direction.VERTICAL, app.activeDocument.selection.bounds[0], SelectionType.INTERSECT);
app.activeDocument.selection.deselect();
app.preferences.rulerUnits = old_units;