• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Move the selection below the guide line

Explorer ,
Apr 20, 2023 Apr 20, 2023

Copy link to clipboard

Copied

How to move the selection to the bottom of the reference line, the reference line is horizontal, the coordinates of the selection are random, how to move the selection up to the bottom of the reference line through the script? Thank you 

TOPICS
Actions and scripting

Views

660

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 20, 2023 Apr 20, 2023

Perhaps something like this?

 

/*
Move Selection Top to Horizontal Guide Coordinate.jsx
v1.0 - 20th April 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/move-the-selection-below-the-guide-line/td-p/13738648
*/

#target photoshop

var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if (activeDocument.guides.length === 1 && activeDocument.guides[0].direction == Direction.HORIZONTAL) {
    var hGuidePos = activeDocument.guides[
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 20, 2023 Apr 20, 2023

Copy link to clipboard

Copied

Just to be clear on terminology, by reference line, do you mean guide? As in View menu > New Guide?

 

If so, will there only be one guide – or at least only one horizontal guide?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2023 Apr 20, 2023

Copy link to clipboard

Copied

Perhaps something like this?

 

/*
Move Selection Top to Horizontal Guide Coordinate.jsx
v1.0 - 20th April 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/move-the-selection-below-the-guide-line/td-p/13738648
*/

#target photoshop

var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if (activeDocument.guides.length === 1 && activeDocument.guides[0].direction == Direction.HORIZONTAL) {
    var hGuidePos = activeDocument.guides[0].coordinate.value;
    try {
        activeDocument.selection.bounds;
        var selTop = activeDocument.selection.bounds[1].value;
        var vMove = selTop - hGuidePos;
        moveSel(0, -vMove);
    } catch (e) {
        alert("There is no active selection!");
    }
} else {
    alert("There are multiple guides and or the guide is vertical!");
}
app.preferences.rulerUnits = savedRuler;

function moveSel(horizontal, vertical) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putProperty(s2t("channel"), s2t("selection"));
    descriptor.putReference(s2t("null"), reference);
    descriptor2.putUnitDouble(s2t("horizontal"), s2t("pixelsUnit"), horizontal);
    descriptor2.putUnitDouble(s2t("vertical"), s2t("pixelsUnit"), vertical);
    descriptor.putObject(s2t("to"), s2t("offset"), descriptor2);
    executeAction(s2t("move"), descriptor, DialogModes.NO);
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 20, 2023 Apr 20, 2023

Copy link to clipboard

Copied

LATEST

Thank you for your help. Thank you 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines