Skip to main content
Known Participant
April 22, 2022
Answered

Script to delete text and path items present outside the Artboard

  • April 22, 2022
  • 2 replies
  • 1426 views

Hello All,

 

I just want ask, whethere any possibilites are there in scripting to delete the text and path items present outside the artboard.

 

For Example:

I want to delete the rectangles and text present outside artboard for 100's of files. As of now, I am doing manually. 

 

Please let me know any possible and quick way using scripting.

This topic has been closed for replies.
Correct answer CarlosCanto

here's a very crude alternative for educational purposes

 

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

 

2 replies

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
April 22, 2022

here's a very crude alternative for educational purposes

 

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

 

Surya24Author
Known Participant
April 23, 2022

Thank You So Much @CarlosCanto 

femkeblanco
Legend
April 22, 2022

This should delete anything partly or completely outside the one artboard:

 

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[0] < b2[0] || b1[2] > b2[2]) || 
        (b1[1] > b2[1] || b1[3] < b2[3])) {
        items[i].remove();
    }
}

 

This should delete anything completely outside the one artboard:

 

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].remove();
    }
}

 

Surya24Author
Known Participant
April 23, 2022

Thank You So Much @femkeblanco