Skip to main content
Known Participant
August 5, 2023
Question

Script to select all images on artboard

  • August 5, 2023
  • 1 reply
  • 865 views

Hi all

I have an artboard that contian images and shapes around it

I need script that select all images , move them ( cut ) to a new layer , shapes around images in move to another layer without images

Thanks

This topic has been closed for replies.

1 reply

femkeblanco
Legend
August 5, 2023
var doc = app.activeDocument;
doc.layers.add().name = "Images";
doc.layers.add().name = "Linked Files";
doc.layers.add().name = "Other";
for (var i = 0; i < doc.pageItems.length; i++) {
    if (doc.pageItems[i].typename == "RasterItem") {
        move(doc.pageItems[i], doc.layers["Images"]);
    } else if (doc.pageItems[i].typename == "PlacedItem") {
        move(doc.pageItems[i], doc.layers["Linked Files"]);
    } else {
        move(doc.pageItems[i], doc.layers["Other"]);
    }
}
function move(what, where) {
    what.move(where, ElementPlacement.PLACEATEND);
}
Known Participant
August 5, 2023

Thanks for Your reply

But the script work on some images and some images not work

Ex : I want all images move to layer 1 without its frames

all frames move to layer 2 without images

Here is the pdf file open it in illustrator

pixxxelschubser
Community Expert
Community Expert
August 5, 2023

Hi @r28071715i111 

A little side note:

The script from @femkeblanco works exactly as you described. Unfortunately, you forgot to mention that there are dozens of nested clipping groups in your file and furthermore compound path items in some groups exists.

 

It might also be helpful to specify the correct Illustrator version. Because not every helper here in the forum always uses the latest version.