1 Reply Latest reply on Nov 26, 2013 7:28 AM by JohnDevlon

    [CS5.5][JS] Replace anchored frames by library item

    JohnDevlon Level 1

      Hi,

       

      I have multiple documents containing many icons as anchored frames in many text flows. Now, I have to replace them by another icon from a library.

       

      Does anyone have any idea on how to replace the icon?

       

      The code I have so far...

       

      var myLib = getLibByName(app.libraries, "Icons.indl" );

      var myAsset = getAssetByName(myLib, "New");  

      for (var n = 0; n < app.activeDocument.allPageItems.length; n++){

          var myItem = app.activeDocument.allPageItems[n];

       

          if (myItem.constructor.name == "Rectangle"){

                  if (myItem.graphics.length == 1){

                          var myImage= myItem.graphics[0];

       

                          if (myImage.itemLink.name == "icon.jpg"){

                              // replace myItem by myAsset

                          }

                  } 

          }

      }

       

      alert("done");

       

       

       

       

      function getAssetByName(myLib, strAssetName){

           var myResult = null;

       

           for (var n = 0; n < myLib.assets.length; n++){

                  if (myLib.assets[n].name == strAssetName){

                      myResult = myLib.assets[n];

                      break;

                  }

           }

       

           return myResult;

      }

       

       

       

      function getLibByName(allLibs, strName){

           var myResult = null;

       

           for (var n = 0; n < allLibs.length; n++){

                  if (allLibs[n].name == strName){

                      myResult = allLibs[n];

                      break;

                  }

           }

       

           return myResult;

      }

       

       

       

      Thanx