Skip to main content
Participating Frequently
October 27, 2022
Answered

How to select Objects outside Artboard ?

  • October 27, 2022
  • 2 replies
  • 1690 views

Hi!

 

how can I select all Objects outside the Artboard?

ps: I don't want to delete them, so no "removeArtboardFluff" function, I want to use them...

 

THX!!

This topic has been closed for replies.
Correct answer femkeblanco

I don't know why it would not work.  Try the conventional way.  (This presumes one artboard and is for items completely outside the artboard.)

app.selection = null;
var doc = app.activeDocument;
var items = doc.pageItems;
for (var i = items.length - 1; i > -1; i--) {
    var b1 = items[i].geometricBounds;
    var b2 = doc.artboards[0].artboardRect;
    if ((b1[2] < b2[0] || b1[0] > b2[2]) || 
        (b1[3] > b2[1] || b1[1] < b2[3])) {
        items[i].selected = true;
    }
}

2 replies

femkeblanco
Legend
October 27, 2022

You could do it the conventional way, by comparing the bounds of items with the bounds of the artboard. A shorter script should be (I cannot test it at present)

app.executeMenuCommand ("selectallinartboard");
app.executeMenuCommand ("Inverse menu item");

 

Participating Frequently
October 28, 2022

Hello femkeblanko,

using this directly in illustrator, the selection works.

But over my script, t´which is driven by an external script runner, it did not work.

The file gets opened, but nothing gets selected...

 

thx & kr

femkeblanco
femkeblancoCorrect answer
Legend
October 28, 2022

I don't know why it would not work.  Try the conventional way.  (This presumes one artboard and is for items completely outside the artboard.)

app.selection = null;
var doc = app.activeDocument;
var items = doc.pageItems;
for (var i = items.length - 1; i > -1; i--) {
    var b1 = items[i].geometricBounds;
    var b2 = doc.artboards[0].artboardRect;
    if ((b1[2] < b2[0] || b1[0] > b2[2]) || 
        (b1[3] > b2[1] || b1[1] < b2[3])) {
        items[i].selected = true;
    }
}
Legend
October 27, 2022

Select and lock all the objects that are on the artboard, then select all to grab the rest. 

Participating Frequently
October 27, 2022

Thanks for your prompt answer!

I meant a Java-script for doing this...