0
Explorer
,
/t5/illustrator-discussions/how-to-delete-the-last-object-an-image-inside-a-layer-using-a-script/td-p/11788573
Jan 27, 2021
Jan 27, 2021
Copy link to clipboard
Copied
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Community Expert
,
Jan 27, 2021
Jan 27, 2021
Hello,
You can try following snippet if it is always last Object
var doc = app.activeDocument;
var _pageItems = doc.pageItems;
_pageItems[_pageItems.length - 1].remove();
Or , if it can be at any position inside the layer, you can traverse and remove the item by following snippet.
var doc = app.activeDocument;
var _pageItems = doc.pageItems;
for (var i = _pageItems.length-1; i > 0; i--) {
if (_pageItems[i].typename== "PlacedItem") {
_pageItems[i].remove();
}
}
Explore related tutorials & articles
Community Expert
,
LATEST
/t5/illustrator-discussions/how-to-delete-the-last-object-an-image-inside-a-layer-using-a-script/m-p/11788609#M261515
Jan 27, 2021
Jan 27, 2021
Copy link to clipboard
Copied
Hello,
You can try following snippet if it is always last Object
var doc = app.activeDocument;
var _pageItems = doc.pageItems;
_pageItems[_pageItems.length - 1].remove();
Or , if it can be at any position inside the layer, you can traverse and remove the item by following snippet.
var doc = app.activeDocument;
var _pageItems = doc.pageItems;
for (var i = _pageItems.length-1; i > 0; i--) {
if (_pageItems[i].typename== "PlacedItem") {
_pageItems[i].remove();
}
}
Best regards
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

