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

delete one guide at a time [2012]

New Here ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

Hi

 

any idea on how to delete/remove one guide at a time pl. I've gone through the forum which clears all the guides but couldnt find any help on deleting guides one at a time.

Any possible solution

TOPICS
Actions and scripting , macOS , Windows

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
Guru ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

With version greater than CS4 guides are part of the Object Model.

app.activeDocument.guides.length;// number of guides in document

app.activeDocument.guides[0].remove();// remove a guide by index

The index is in the order the guides were created.

You can also determine where a guide is by looking at it's coordinate and direction priperties.

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 ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

And for those mere motals using the Ludditian CS2? I noticed that the script listener doesn't pick up on guide deletion. And since they're not part of the the object model it's gonna be quite difficult to remove them (or even move them to off the canvas)

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
Guru ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

Yes, with older versions you are stuck with using Action Manger to work with guides. And as far as I can tell you can't remove a single guide with AM code.

You can remove all guides and you can create guides. I also have code that will let you get info about the current guides in a document. With that you could get the info about the guides in a document, remove all the guides, then add back the ones you want to keep. Not pretty but it should work. Here is the code.

To get guide info:

#target photoshop

app.bringToFront();

/* the info about guides can be found in the photoshop tag hex 35 42 49 4D 04 08

   the length of the tag is found at offset 11. that value is the length to the next tag

   the number of guides can be found at offset 27. From that point the data repeats

   for each guide. 4 bytes for the location. That value / 32 = pixels

   and one byte for type 0 = vert and 1 = horz

   Note: this info is just a best guess from looking at the data

*/

///////////////////////////////////////////////////////////////////////////////

// Function: getGuideInfo

// Description: Saves the document as a temp jpg file

//                        and extracts the info about the guides

//                        in document if any

// Usage: var guides = getGuideInfo( activeDocument );

// Input: Document

// Return: Object: TotalCount property  = number of guides

//                  HorizontalCount property = number of horizontal guides

//                  VerticalCount property = number of vertical guides

//                  Horizontal = horizontal guides

//                  Vertical property = vertical guides

// Source: Modified from http://ps-scripts.com/bb/viewtopic.php?t=3283

///////////////////////////////////////////////////////////////////////////////

function getGuideInfo( doc ) {

   saveOptions = new JPEGSaveOptions();

   // we don't care about image quality in the temp file

   // we do want the smallest file size

   saveOptions.quality = 0;// we don't care about image quality in the temp file

   var tempFile = new File( Folder.temp + '/' +'guideTemp.jpg' );

   // Dupe the doc, make it savable as JPEG, save it, then close the file

   doc = doc.duplicate();

   if( doc.mode == DocumentMode.BITMAP ) doc.changeMode(ChangeMode.GRAYSCALE);

   doc.bitsPerChannel = BitsPerChannelType.EIGHT;

   doc.changeMode(ChangeMode.RGB);

   doc.saveAs(tempFile, saveOptions, true);

   doc.close(SaveOptions.DONOTSAVECHANGES);

  tempFile.encoding = 'BINARY';

  tempFile.open('r');

  var str = tempFile.read();

  tempFile.close();

  tempFile.remove();

   var guideTag = '8BIM\x04\x08';

   var tagPos = str.search(guideTag);

   var guides = new Object;

   guides.toString = function(){ return 'GuideInfo'; }

   var horGuides = new Array;

   var vertGuides = new Array;

   if( tagPos != -1 ) {

      var tagLength = 12 + str.charCodeAt( tagPos + 11 );

      var guideStr = str.substring( tagPos, tagPos+tagLength );

      guides.count = str.charCodeAt( tagPos + 27 );

      var pointer = tagPos + 28;

      for( var i =0; i < guides.count; i++ ){

       //  var n = ((str[pointer] << 3) + (str[pointer+1] << 2) + (str[pointer+2] << 1) + str[pointer+3])/32;

      //var n = Number( '0x'+getHexString( str, pointer )+getHexString( str, pointer+1 )+getHexString( str, pointer+2 )+getHexString( str, pointer+3 ))/32;

             var n = ((str.charCodeAt(pointer)<< 32) + (str.charCodeAt(pointer + 1)<< 16) +

                    (str.charCodeAt(pointer + 2) << 8) + str.charCodeAt(pointer+3))/32;

if  (str.charCodeAt( pointer + 4 ) == 0) {

          //vertical

          vertGuides = insertValueInOrder(vertGuides, n);

       } else {

          //horizontal

          horGuides = insertValueInOrder(horGuides, n);

       }  

        // guides[ i ] =  [ (str.charCodeAt( pointer + 4 ) ? 'horz':'vert'), n ];    

         pointer = pointer + 5;

      }

     guides.HorizontalCount =horGuides.length;

     guides.VerticalCount =vertGuides.length;

     guides.Horizontal = horGuides;

     guides.Vertical = vertGuides;

   }else{

      guides.TotalCount = 0;

     guides.HorizontalCount =0;

     guides.VerticalCount =0;

   }

   function insertValueInOrder(a , n) {

      var b = new Array;

      var i = 0;

      if (a[0] == undefined)

         b[0] = n;

      else {

         while (a < n && i < a.length) {

               b = a;

               i++;

         }

         b = n;

         while (i < a.length) {

            b[i+1] = a;     

            i++;

         }

      }  

      return b;

   }

   return guides;

}

  function fromCharCode(input) {

      output = eval("String.fromCharCode(" + input + ")");

     return output;

   }

// demo

var masterDocument = app.activeDocument;

var guideInfo = getGuideInfo( masterDocument );

var s = "Vertical Guides: " + guideInfo.Vertical + "\nHorizontal Guides: " + guideInfo.Horizontal;

alert(s);

To remove all guides:

function clearAllGuides() {

     var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putEnumerated( charIDToTypeID( "Gd  " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al  " ) );

     desc.putReference( charIDToTypeID( "null" ), ref );

     executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );

};

To add a guide:

function guideLine(position, type,unit) {// from Paul MR

   //units '#Pxl' pixel '#Rlt' =Relative  '#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 );

};

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
Participant ,
Mar 09, 2016 Mar 09, 2016

Copy link to clipboard

Copied

I'm about 3.5 years too late, but here's how to delete a guide by its index:

function removeGuideByIndex(idx) {

   // Build a reference to the guide we want

  var ref = new ActionReference()

  // Guide indexes start at 1 for some reason.

  ref.putIndex(charIDToTypeID('Gd  '), idx+1)

  // Create a descriptor with our reference in it

  var desc = new ActionDescriptor()

  desc.putReference(charIDToTypeID('null'), ref)

  // Execute the delete action on our descriptor.

  executeAction(charIDToTypeID('Dlt '), desc, 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
Contributor ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

I tried the script but does not work for me.

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
Participant ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

Can you be more specific about what doesn't work? It's working fine for me in CC+

To test:

1. Create a new document.

2. Create a guide on the left side, then one on the right side.

3. Run the function above with removeGuideByIndex(0)

The guide on the left will disappear, as it was the first guide added.

*I'm making the assumption you are familiar with how JavaScript works. If not, the code above is just a function declaration and won't do anything unless you know your guide's index and how to call a function with 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
Contributor ,
Mar 11, 2016 Mar 11, 2016

Copy link to clipboard

Copied

I tried in every way but does not go

Use photoshop cc2014

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
New Here ,
May 11, 2024 May 11, 2024

Copy link to clipboard

Copied

For anyone looking to do this now almost 10 years in the future, the code would look something like this:

async function deleteAGuide() {
   await executeAsModal(async () => {
      app.activeDocument.guides[0].delete();
   });
}

Good luck

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 ,
May 12, 2024 May 12, 2024

Copy link to clipboard

Copied

quote

For anyone looking to do this now almost 10 years in the future, the code would look something like this:

async function deleteAGuide() {
   await executeAsModal(async () => {
      app.activeDocument.guides[0].delete();
   });
}

Good luck


By @things_and_things


Thanks for sharing! Just to clarify, this is UXP .psjs code, not the more common legacy ExtendScript .jsx code.

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 ,
May 12, 2024 May 12, 2024

Copy link to clipboard

Copied

quote

For anyone looking to do this now almost 10 years in the future, the code would look something like this:

async function deleteAGuide() {
   await executeAsModal(async () => {
      app.activeDocument.guides[0].delete();
   });
}

Good luck


By @things_and_things

 

Hmmm, nothing happens, even when adding the expected call to the function:

 

deleteAGuide();

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 ,
May 12, 2024 May 12, 2024

Copy link to clipboard

Copied

I'm probably missing some purpose here - just wanted to point out that you can delete one guide at a time manually - click it with the move tool to activate it (it changes color), then hit the Delete key.

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 ,
May 12, 2024 May 12, 2024

Copy link to clipboard

Copied

quote

I'm probably missing some purpose here - just wanted to point out that you can delete one guide at a time manually - click it with the move tool to activate it (it changes color), then hit the Delete key.


By @D Fosse

 

As the topic is labelled actions/scripting, the assumed context is to do so programmatically.

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 ,
May 12, 2024 May 12, 2024

Copy link to clipboard

Copied

I suppose I was just trying to wrap my head around how a script can know which guide you want to delete 😉

 

Now I know I'm missing something here, but that's fine 😄 Carry on, don't mind me -

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 ,
May 12, 2024 May 12, 2024

Copy link to clipboard

Copied

quote

I suppose I was just trying to wrap my head around how a script can know which guide you want to delete 😉

 

Now I know I'm missing something here, but that's fine 😄 Carry on, don't mind me -


By @D Fosse


That is true and a fair valid question . An Individual guide can have scriptable properties, such as horizontal or vertical and the associated coordinate.

 

The collection of guides can be identified by the first guide or the last guide, or the second guide added etc.

 

So a pretty blunt tool depending on what one needs to do compared to using the mouse.

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 ,
May 12, 2024 May 12, 2024

Copy link to clipboard

Copied

LATEST
quote

Now I know I'm missing something here

By @D Fosse

 

I'm with you on this! Select and Delete for one guide is easy. Was it the same 14 years ago in 2012 when the OP asked the question?

 

Jane

 

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