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

• Javascript to embed ALL linked images into the AI file via script (bug?)

Enthusiast ,
Jun 26, 2019 Jun 26, 2019

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

  1. #target illustrator 
  2.  
  3. embedAllImages(); 
  4.  
  5. function embedAllImages(){ 
  6.     var placedArt = app.activeDocument.placedItems; 
  7.     if ( placedArt.length == 0 ) { return; } 
  8.     for ( var i = placedArt.length-1; i >= 0; i-- ) { 
  9.         placedArt.embed(); 
  10.     }; 
  11. }; 

Thank you

- Dimitri

TOPICS
Scripting
2.8K
Translate
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
Adobe
Enthusiast ,
Jun 26, 2019 Jun 26, 2019
Translate
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
Enthusiast ,
Jun 26, 2019 Jun 26, 2019

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:

screenshot_-2019-06-26-at-21.27.56.jpg

- Dimitri

Translate
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
Enthusiast ,
Jun 26, 2019 Jun 26, 2019

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...

Translate
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
Participant ,
Jan 22, 2024 Jan 22, 2024
LATEST

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

 

Translate
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