Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Illustrator script embed selected art in selected layer

New Here ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

Hi there,

 

I have an Illustrator document with multiple layers and multiple layers with linked images/art in them. I would like to with a script select a specific layer and embed all images in the selecte layer only.

 

This is the script I have but as soon as I have multiple images in the layer it will only embed one of the images.

 

var i = 1
var doc = app.activeDocument;
var myLayers = doc.layers;

EmbedTestLayer();

function EmbedTestLayer()
{
//Layers visible and unlocked
for (a=0; a<myLayers.length; a++){
myLayer = myLayers[a];
myLayer.visible = true;
myLayer.locked = false;
}
}
try{
//Deselect all objects
app.activeDocument.selection = null;

//Embed objects in layer
myLayers.getByName ("Test Layer").hasSelectedArtwork = true;
placedArt = app.activeDocument.placedItems[i];
placedArt.embed("Test Layer");
}
catch (e) {}
 
Test Layer is the layer that I want to select as well as all elements/sublayers and then embed the Art.
 
Help will be greately appreciated.
TOPICS
Scripting

Views

90

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

Advocate , Oct 18, 2021 Oct 18, 2021
var doc = app.activeDocument; var myLayers = doc.layers; EmbedTestLayer(); function EmbedTestLayer() { for (var a = 0; a < myLayers.length; a++){ myLayer = myLayers[a]; myLayer.visible = true; myLayer.locked = false; } } try { var targetLayer = myLayers["Test Layer"]; var items = targetLayer.placedItems; for (var i = items.length - 1; i > -1; i--) { items[i].embed(); } } catch (e) {}

Likes

Translate

Translate
Adobe Community Professional ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

The variable "i" has not changed its value to 1. So only one image is processed.

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
Advocate ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

var doc = app.activeDocument;
var myLayers = doc.layers;
EmbedTestLayer();
function EmbedTestLayer() {
    for (var a = 0; a < myLayers.length; a++){
        myLayer = myLayers[a];
        myLayer.visible = true;
        myLayer.locked = false;
    }
}
try {
    var targetLayer = myLayers["Test Layer"];
    var items = targetLayer.placedItems;
    for (var i = items.length - 1; i > -1; i--) {
        items[i].embed();
    }
}
catch (e) {}

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
New Here ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

LATEST

Femke, 

 

You are the best! Thank you very much!

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