Skip to main content
Participating Frequently
Oct 27, 2022 1:39 PM UTC
Answered

How to select Objects outside Artboard ?

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 is closed to new replies. Start a new post to keep the conversation going.
femkeblanco
femkeblancoCorrect answer
Legend
Oct 28, 2022 5:04 PM UTC

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;
    }
}

8 replies

femkeblanco
Legend
Oct 27, 2022 2:13 PM UTC

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");

 

Translate
Participating Frequently
Oct 28, 2022 8:58 AM UTC

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

Translate
femkeblanco
femkeblancoCorrect answer
Legend
Oct 28, 2022 5:04 PM UTC

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;
    }
}
Translate
Legend
Oct 27, 2022 1:56 PM UTC

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

Translate
Participating Frequently
Oct 27, 2022 2:00 PM UTC

Thanks for your prompt answer!

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

Translate