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

Photoshop Action To Create Guides From Marquee Selection

Engaged ,
Nov 12, 2016 Nov 12, 2016

Copy link to clipboard

Copied

I looked around on the forums for this answer, but I couldn't find anything specific.

I would like to be able to use the marquee tool to define an area and then create an action where guidelines will be placed against the marquee selection. I may be overthinking this, but is this even possible?

Thanks.

TOPICS
Actions and scripting

Views

2.7K

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
Adobe
Community Expert ,
Nov 12, 2016 Nov 12, 2016

Copy link to clipboard

Copied

Shan-Dysigns​

Hmmh?

I do not have an action for you but you can try a script snippet:

// regards pixxxel schubser

var aDoc = activeDocument;

var Sel = aDoc.selection.bounds;

aDoc.guides.add(Direction.VERTICAL, Sel[0].as('px'));

aDoc.guides.add(Direction.HORIZONTAL, Sel[1].as('px'));

aDoc.guides.add(Direction.VERTICAL, Sel[2].as('px'));

aDoc.guides.add(Direction.HORIZONTAL, Sel[3].as('px'));

Have fun

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
Engaged ,
Feb 17, 2017 Feb 17, 2017

Copy link to clipboard

Copied

I create a blank document, use the marquee tool to draw a selection, enact the script, and receive this error.

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 ,
Feb 17, 2017 Feb 17, 2017

Copy link to clipboard

Copied

What are your ruler units set to? That script should set the ruler to get the selection bounds in pixels. It does not

// regards pixxxel schubser 

var orig_ruler_units = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS 

var aDoc = activeDocument; 

var Sel = aDoc.selection.bounds; 

 

aDoc.guides.add(Direction.VERTICAL, Sel[0].as('px')); 

aDoc.guides.add(Direction.HORIZONTAL, Sel[1].as('px')); 

aDoc.guides.add(Direction.VERTICAL, Sel[2].as('px')); 

aDoc.guides.add(Direction.HORIZONTAL, Sel[3].as('px')); 

app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings

JJMack

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
Engaged ,
Feb 17, 2017 Feb 17, 2017

Copy link to clipboard

Copied

Ruler units were px when I tested the script. I'm pretty advanced in javascript/jQuery (web development), but I wish I had the time to experiment in Photoshop.

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 ,
Feb 17, 2017 Feb 17, 2017

Copy link to clipboard

Copied

Shan-Dysigns  wrote

Ruler units were px when I tested the script. I'm pretty advanced in javascript/jQuery (web development), but I wish I had the time to experiment in Photoshop.

What seem strange is you are getting a error on line 13. that statement  was line 6 in the first script and line 7 in the second  script neither scripts had 13 lines the were shorter. Please post the script your using...

JJMack

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 ,
Feb 17, 2017 Feb 17, 2017

Copy link to clipboard

Copied

I can not make it fail no matter what selection I create it sets guides for the selections bounds.  Wait are you using CS2 if I remember selection bounds was broken in cs2?

Capture.jpg

It does fail in CS2 but with a different error than you get What version of Photoshop are you using?

Capture.jpg

JJMack

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
Engaged ,
Feb 17, 2017 Feb 17, 2017

Copy link to clipboard

Copied

I am still using CS4, so maybe the issue carried over from CS2.

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 ,
Feb 17, 2017 Feb 17, 2017

Copy link to clipboard

Copied

Post the script your using something is strange.

JJMack

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
Engaged ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

My notifications must be turned off. I just happened to catch your reply today.

The script I am using is the one supplied above from

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 ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

If you set ruler units to pixels, there is no need to do the same in the code again.

// regards pixxxel schubser

var orig_ruler_units = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS

var aDoc = activeDocument;

var Sel = aDoc.selection.bounds;

aDoc.guides.add(Direction.VERTICAL, Sel[0]);

aDoc.guides.add(Direction.HORIZONTAL, Sel[1]);

aDoc.guides.add(Direction.VERTICAL, Sel[2]);

aDoc.guides.add(Direction.HORIZONTAL, Sel[3]);

app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings

Have fun

Btw

If I remember right, this will work correct in CS5 and later.

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
Guide ,
Mar 04, 2017 Mar 04, 2017

Copy link to clipboard

Copied

Untested but should work in CS2 or newer so long as a selection has been made.

var startRulerUnits = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

var bnds = getSelectionBounds();

guideLine(bnds[1],"Hrzn",'#Pxl');

guideLine(bnds[3],"Hrzn",'#Pxl');

guideLine(bnds[0],"Vrtc",'#Pxl');

guideLine(bnds[2],"Vrtc",'#Pxl');

preferences.rulerUnits = startRulerUnits;

function guideLine(position, type,unit) {

    //units '#Pxl' pixel '#Rlt' =Relatiive  '#Prc' = percent

    // types: 'Vrtc' & 'Hrzn'

    var desc = new ActionDescriptor();

        var desc2 = new ActionDescriptor();

        desc2.putUnitDouble( charIDToTypeID('Pstn'), charIDToTypeID(unit), position);

        desc2.putEnumerated( charIDToTypeID('Ornt'), charIDToTypeID('Ornt'), charIDToTypeID(type) );

    desc.putObject( charIDToTypeID('Nw  '), charIDToTypeID('Gd  '), desc2 );

    executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );

};

function getSelectionBounds() {

    var doc = activeDocument;

    var l = doc.artLayers.add();

    doc.selection.fill(app.foregroundColor);

    var bnds = l.bounds;

    var hs = doc.historyStates;

    if (hs[hs.length-2].name == "Layer Order") {

      doc.activeHistoryState = hs[hs.length-4];

    } else {

      doc.activeHistoryState = hs[hs.length-3];

    }

    for (var i = 0; i < bnds.length; i++) {

      bnds = bnds.value;

    }

    return bnds;

};

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 ,
Mar 04, 2017 Mar 04, 2017

Copy link to clipboard

Copied

Selection Bounds does not work in CS2 I had to code around that bug in CS2

JJMack

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
Guide ,
Mar 04, 2017 Mar 04, 2017

Copy link to clipboard

Copied

I am not using selection bounds, I am using Layer bounds and that does work in CS2.

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 ,
Mar 05, 2017 Mar 05, 2017

Copy link to clipboard

Copied

I did not look at the code I just read the function name Using Layer bounds is how I coded around the selection bounds bug in cs2.

JJMack

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
Engaged ,
Apr 22, 2017 Apr 22, 2017

Copy link to clipboard

Copied

LATEST

My email notifications must be turned off because I just now noticed your reply.

Your code worked. I know javascript, but not enough when it comes to Photoshop, so I can somewhat understand the code, but not necessarily what makes it work. The code worked in all the ways I would try to apply it, so thanks for providing it.

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