• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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
Scripting

Views

260

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

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

 

 

Votes

Translate

Translate
Adobe
Community Expert ,
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

Votes

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