• Javascript to embed ALL linked images into the AI file via script (bug?)
Copy link to clipboard
Copied
Hello -
I "copy-paste" a couple of different snippet of code to embed all linked images into the AI file.
Apparently it works for a couple of them but for some other, they jumps/moves of position before they are embed…
What happen?
Is that a know "bug"?
I found this on the net -> https://graphicdesign.stackexchange.com/questions/119214/illustrator-javascript-to-embed-linked-imag...
Hereunder some snippet of code I have tried:
if ( app.documents.length > 0 ) { while ( app.activeDocument.placedItems.length > 0 ) { placedArt = app.activeDocument.placedItems[0]; placedArt.embed(); }
}
Another
- #target illustrator
- embedAllImages();
- function embedAllImages(){
- var placedArt = app.activeDocument.placedItems;
- if ( placedArt.length == 0 ) { return; }
- for ( var i = placedArt.length-1; i >= 0; i-- ) {
- placedArt.embed();
- };
- };
Thank you
- Dimitri
Explore related tutorials & articles
Copy link to clipboard
Copied
Hello again : -)
Why would something like this guy (sean.ryan) is proposing would work (vs. the "classic way")?
https://graphicdesign.stackexchange.com/questions/119214/illustrator-javascript-to-embed-linked-imag... https://graphicdesign.stackexchange.com/questions/119214/illustrator-javascript-to-embed-linked-imag...
Thank you,
- Dimitri
Copy link to clipboard
Copied
What's really strange to me…
Is that when I run the follow piece of code at once some of "links" are moved from their orignal place (two appear in the middle of the active artboard. Some of them are even resized randomly.
But when I run these two "loops" separately it works!
try {
if ( app.documents.length > 0 ) {
// while ( app.activeDocument.placedItems.length > 0 ) {
for (var p = 0; p <= app.activeDocument.placedItems.length; p++) {
placedArt = app.activeDocument.placedItems
;
placedArt.embed();
}
}
} catch(err) {
while ( app.activeDocument.placedItems.length > 0 ) {
placedArt = app.activeDocument.placedItems[0];
placedArt.embed();
}
}
Hereunder is a screenshot of the "LINKS" palette:
- Dimitri
Copy link to clipboard
Copied
Hello -
Could a "Timeout" function help me in this particular case?
Something like:
setTimeout(myFunction, 3000);
Launch the first loop, and after a small timeout,
launch the second loop.
Thank you...
Copy link to clipboard
Copied
Old topic, but maybe this will help someone else
I found that putting an app.redraw() into my embed loop solved my problem. I was randomly having images change size/positions when embeding via scripting. Doing the same thing manually would embed as expected, but something about the script was messing with some of them. The redraw seemed to fix the few that I tested this with.
for (var e = app.activeDocument.placedItems.length - 1; e >= 0; e--) {
var PlacedLink = app.activeDocument.placedItems[e]
if (!PlacedLink.hidden) {
try {
PlacedLink.embed();
} catch (e) {
/*nothing*/
}
app.redraw()
}
}

