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

Explorer ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

Copied

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

TOPICS
How to, Scripting

Views

92

Likes

Translate

Translate

Report

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

correct answers 1 Correct Answer

Adobe Community Professional , 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(); } }

Likes

Translate

Translate
Adobe Community Professional ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

Copied

LATEST

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
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines