1 Reply Latest reply on Oct 3, 2014 10:42 PM by Sajeev Sridharan

    Select Image after Placing

    BEGINNER_X Level 3

      Hi Legends,

       

      With the help of forum, I developed the below script.

       

      My request is for Math type jobs, find the content and place the Image //working fine

       

      But for another request, I need to Select the image again.   //need your help

       

      var myDoc = app.activeDocument;
      
      //to get image path
      var myFilePath = app.activeDocument.filePath;
      var myLinksPath = myFilePath + "/" + "links";
      var myArtPath = File(myLinksPath);
      var myArtFiles = myArtPath.getFiles("*.eps");
      
              
      app.findGrepPreferences = app.changeGrepPreferences = null;
      app.findGrepPreferences.findWhat = "<<<.+?>>>";
      var _equFound = app.activeDocument.findGrep();
      
      for(e=0; e<_equFound.length; e++)
      {
          var _equ_Content = _equFound[e].contents;                         //1
          var myFinalContents = String(_equFound[e].contents).replace(/>>>/, "").replace(/<<</,"");
          
              for(j=0; j<myArtFiles.length; j++)
              {
                  var myArtName = myArtFiles[j].name;
                  var myReplace = myArtName.replace(/\.eps/, "")
                  var myFinalImageName = String(myReplace);
      
                  if(myFinalContents.indexOf(myFinalImageName) != -1)
                  {
                          _equFound[e].place(File(myArtFiles[j]));     //place the image
                          
                          
                          //NEED HELP FOR THE BELOW LINE
      //~                     File(myArtFiles[j]).select();
                          app.selection[0].anchoredObjectSettings.anchorYoffset = 10;    //Error found here
                      }
               }
        }
      

       

       

      Regards

      Siraj

        • 1. Re: Select Image after Placing
          Sajeev Sridharan Level 4

          Try this,

           

          //to get image path  
          var myFilePath = app.activeDocument.filePath;  
          var myLinksPath = myFilePath + "/" + "links";  
          var myArtPath = File(myLinksPath);  
          var myArtFiles = myArtPath.getFiles("*.eps");  
          app.findGrepPreferences = app.changeGrepPreferences = null;  
          app.findGrepPreferences.findWhat = "<<<.+?>>>";  
          var _equFound = app.activeDocument.findGrep();  
          
          
          for(e=0; e<_equFound.length; e++)  
          {  
              var _equ_Content = _equFound[e].contents;                         //1  
              var myFinalContents = String(_equFound[e].contents).replace(/>>>/, "").replace(/<<</,"");  
                  for(j=0; j<myArtFiles.length; j++)  
                  {  
                      var myArtName = myArtFiles[j].name;  
                      var myReplace = myArtName.replace(/\.eps/, "")  
                      var myFinalImageName = String(myReplace);  
                        if(myFinalContents.indexOf(myFinalImageName) != -1)  
                      {  
                              var eqFrame = _equFound[e].place(File(myArtFiles[j]));     //place the image  
                                
                              eqFrame[0].parent.select();
                              app.selection[0].anchoredObjectSettings.anchorYoffset = 10;    //Now it is working fine  
                              }
                          }
                      }
          
          

           

           

          Vandy