Home > InDesign Scripts > Delete guides in document

Delete guides in document

Guides are very good helpers when you work but sometimes we want to get rid of all guides. It’s easy when you have few pages, with one layer, but if you have 100+ pages, with hundreds of guides, it can become a pain to remove all of them.

There is shortcut ‘Ctrl+Alt+G’ for selecting all guides, but that is just for active page/spread, but what about master pages, and other pages? Luckily we can do it through scripting. So, let’s get to work.

As I said, we can delete guides through script, and it’s very easy to achieve. First, we will delete all guides in document. This will delete guides on pages, layers and also on all master pages.

var myDoc = app.activeDocument;
if(myDoc.guides.length > 0){
    myDoc.guides.everyItem().remove();
}

If we want to delete guides just on pages, and leave guides on master pages just alter 1st like this:

var myDoc = app.activeDocument.spreads.everyItem();

Another situation. We want to delete just guides on current page. Line 1 should look like this:

var myDoc = app.activeWindow.activePage;

Delete all guides on active spread:

var myDoc = app.activeWindow.activeSpread;

If we have loop in script, and want to delete guides on pages that are processed in loop, we can alter first line like this: (keep in mind that first page of document is 0)

var myDoc = app.activeDocument.pages[i];

(where is ‘i’ variable from loop)

Deleting guides from master pages. This will delete guides on all master pages. Again alter 1st line like this:

var myDoc = app.activeDocument.masterSpreads.everyItem();

And the last example is to delete all guides on master pages, but with little difference. It will delete guides just on active page applied master. So if we are on page 4, and applied master is ‘B-Master’, guides will be deleted just on ‘B-Master’. Alter 1st line like this:

var myDoc = app.activeWindow.activePage.appliedMaster;

You can combine this examples like delete all guides on current page with deleting guides on applied master page.

So, that’s it, I hope you will find this useful.

  1. July 26, 2010 at 16:23

    Isn’t
    var myDoc = app.activeDocument.pages[app.activeWindow.activePage.name-1];
    a bit complex ?
    When
    app.activeWindow.activePage is enough to set a reference to the activePage ?
    You may also talk to the spread itself with
    app.activeWindow.activeSpread
    Loic

  2. July 26, 2010 at 17:15

    Yeah! Thanks!
    I was focused on ‘app.activeDocument’ approach, so I overlooked that😀
    I will correct this, and also add ‘activeSpread’ method.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: