How to Delete the Last Object (an Image) inside a Layer using a Script?

Explorer ,
Jan 27, 2021

Copy link to clipboard

Copied

B11374C8-9B43-4AB2-88DD-D6D09F8D3756.jpeg

TOPICS
How to, Scripting

Views

64

Likes

Translate

Translate

Report

Report
Reply
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

Adobe Community Professional , Jan 27, 2021
Charu Rajput Adobe Community Professional , 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(); } }    

Likes

Translate

Translate
Jump to answer Jump to answer
Adobe Community Professional ,
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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more