16 Replies Latest reply on Jun 1, 2016 5:52 AM by zhangm7455560

    embed() bug - rescales to original size

    dovidgold Level 1

      I have a script that finds goes to all placedItems and embeds them. My code is simple enough:

      function embedAllImages(){

          placedArt = app.activeDocument.placedItems;

          if (placedArt < 0) {

          return;

              } else {

          for ( var i = placedArt.length-1; i >= 0; i-- ) {

          placedArt[i].embed();

          }

      }

      }

      In most cases it does as expected. However I found a strange case where after embedding, it scales the image to the original size.

      Here's how to replicate the bug:

      Create new .psd file in photoshop, can be one layer. Place it into illustrator twice, or duplicate it. Scale both images bigger or smaller.

      Now run this simplified version of the script:

      app.activeDocument.placedItems[0].embed();

      app.activeDocument.placedItems[0].embed();

      (note after embedding the first image, the next image gets index 0 since it's now the only placed item).

      Now you'll see one of the images rescaled to it's original size.

      If you do "placedItems[1].embed();" on the first line then it'll execute as expected. However I have found situations where even that resulted in the bug. So I can't use that as a work around.

      Any ideas?

      Thanks!