11 Replies Latest reply on Nov 11, 2011 7:37 AM by yajiv_viki

    Place text frame on the linked image...!

    yajiv_viki Level 2

      Hi Everyone!

       

      Its possible to place text frame on the linked image using java script.

       

      the text frame text is name of the linked image. anyone to help me if possible...?


      Thanks in advance.

       

       

      -yajiv



        • 1. Re: Place text frame on the linked image...!
          Ten A Adobe Community Professional

          Hi, Try this one.

           

          var slct = app.activeDocument.selection[0];

          var sourceFolder = "/"; //set images path

          var fNm ="";

          if (slct=="[object TextFrame]") {

              fNm = sourceFolder + slct.contents;

              var f = new File (fNm);

              if(f.exists){

                  slct.contents = "";

                  slct.place(f);

                  slct.fit(FitOptions.PROPORTIONALLY);

                  slct.fit(FitOptions.CENTER_CONTENT);

                  }

              }

           

          You can choose images path to set "sourceFolder" variable. But TextFrames contents contain full-path of Image files, remove sourceFolder variable and set fNm like below:

           

          fNm = slct.contents;

           

          Ten

          • 2. Re: Place text frame on the linked image...!
            yajiv_viki Level 2

            Hi Ten,

             

            Thansk for your reply.

             

            it is not working. i need blow mentioned step to script.

             

            In new document has two image was placed. If i run the script

             

            • The text frame is placed above linked image. the text frame content is name of linked image.
            • The text frame aligned centre of the placed image.

             

            It's possible...?

            Help me......!

             

            -yajiv

            • 3. Re: Place text frame on the linked image...!
              Ten A Adobe Community Professional

              Hi, I rewrite this one,

               

              var tgt = app.activeDocument.rectangles;

               

              for (i=0;i<tgt.length;i++){

                  myCaption = app.activeDocument.textFrames.add();

                  myCaption.textFramePreferences.verticalJustification =

                      VerticalJustification.BOTTOM_ALIGN

                  myCaption.contents = tgt[i].graphics[0].itemLink.name

                  myCaption.paragraphs[0].justification =

                      Justification.CENTER_ALIGN;

                  bnds = tgt[i].visibleBounds;

                  myCaption.visibleBounds =

                      [bnds[0]-6, bnds[1], bnds[0]-1,bnds[3]];

                  }

               

              How about it?

               

              Ten

              • 4. Re: Place text frame on the linked image...!
                yajiv_viki Level 2

                Hi Ten.

                 

                Thanks Ten..!

                 

                This script i want. Once again thank for you support...

                 

                One doubt can you clarify that...

                 

                I'm working in MAC platform. If there is any possibility to search filename from server using javascript.

                 

                 

                -yajiv

                • 5. Re: Place text frame on the linked image...!
                  Ten A Adobe Community Professional

                  Servers mounts under "/Volumes". When you mount directory name of "public", you can access below

                   

                  /Volumes/public/

                   

                  And you can get file list below:

                   

                  var myFolder = new Folder("/Volumes/public/");

                  var myFiles = myFolder.getFiles();

                  var myList = "";

                  for (i=0;i<myFiles.length;i++){

                      myList += myFiles[i].name + "\n";

                      }

                  alert(myList);

                   

                  Ten

                  1 person found this helpful
                  • 6. Re: Place text frame on the linked image...!
                    yajiv_viki Level 2

                    Hi Ten,

                     

                    Its awesome...!!!

                    also its possible to get subfolder files....?

                     

                    -yajiv.

                    • 7. Re: Place text frame on the linked image...!
                      Ten A Adobe Community Professional

                      We can use File's "creator" property to determin File or Folder.

                      If target object is "File" then return creator string, but target object is "Folder", in this case return "undefined".

                       

                      var myFolder = new Folder("/Volumes/public/");

                      var myFiles = myFolder.getFiles();

                      var myList = "";

                      for (i=0;i<myFiles.length;i++){

                          if(myFiles[i].creator==undefined){

                              myFiles2= myFiles[i].getFiles();

                              for (j=0;j<myFiles2.length;j++){

                                  myList += myFiles[i].name +

                                      "/" + myFiles2[j].name + "\n";

                                  }

                              } else {

                                  myList += myFiles[i].name + "\n";

                                  }

                          }

                       

                      alert(myList);

                       

                      It checks first child of current folder.

                       

                      Ten.

                      1 person found this helpful
                      • 8. Re: Place text frame on the linked image...!
                        yajiv_viki Level 2

                        Ten,

                         

                        Chance less...... you rock..!!!

                         

                        Thanks you support....!. its really helpful and Thanks lot....

                         

                        It's possible to search filename in subfolder....?

                         

                        Ten, Do you have any reference document javascript(.jsx) (or) any website name for java script reference.

                         

                        Please let me inform.

                         

                         

                        Thanks for Cheers!!!

                         

                        - yajiv

                        • 9. Re: Place text frame on the linked image...!
                          yajiv_viki Level 2

                          Hi Ten,

                           

                               Finally I modify your code to get search filename from Subfolders.

                           

                          Here the code...

                           

                          var myFolder = new Folder("A:\Workout/Indesign/Automation/");

                          var myFiles = myFolder.getFiles();

                          var myList = "";

                              for (i=0;i<myFiles.length;i++){

                                  if(myFiles[i].creator==undefined){

                                      var myFiles2= myFiles[i].getFiles();

                                          for (j=0;j<myFiles2.length;j++){

                                              if(myFiles2[j].creator==undefined){

                                                  var myFiles3= myFiles2[j].getFiles();

                                                  for (k=0;k<myFiles3.length;k++){

                                                      //myList += myFiles[i].name + "/" + myFiles2[j].name+ "/" + myFiles3[k].name + "\n";

                                                          if(myFiles3[k].name=="sample.tif")

                                                              var myfile="File found - "+myFiles[i].name + "/" + myFiles2[j].name+ "/" + myFiles3[k].name;

                                                          else

                                                               var myfile="File not found"

                                                              }

                                                          }

                                                      }

                                                  }

                                              }

                           

                          alert(myfile);

                           

                          Thanks Ten!!!

                          you are legend....!!!

                           

                          - yajiv

                          • 10. Re: Place text frame on the linked image...!
                            Ten A Adobe Community Professional

                            Hi, yajiv.

                            If you want search more deeper, using recursive function is better way.

                            Sample script is below:

                             

                            var myFolder = new Folder("/Volumes/public/agata");

                            alert (getFiles(myFolder));

                             

                            function getFiles (obj) {

                                var str = "";

                                var myList = obj.getFiles();

                                for (var i=0;i<myList.length;i++){

                                    if (myList[i].creator!=undefined) {

                                        str += myList[i].fullName + "\n";

                                        } else {

                                            str += getFiles(myList[i]) + "\n";

                                            }

                                    }

                                return str;

                                }

                             

                            and... http://forums.adobe.com/thread/668578 as reference

                             

                            Ten

                            • 11. Re: Place text frame on the linked image...!
                              yajiv_viki Level 2

                              Hi Ten,

                               

                              It's awesome script....

                               

                              you are really Gr8!!! .I complicate small things to big. this script ia really help me further innovation.

                               

                              Thanks friend!!!

                               

                              with friendly,

                               

                              - yajiv