14 Replies Latest reply on Feb 12, 2009 8:03 AM by Peter Kahrel

    Extracting info from Links panel

    GilsonAtlantic
      Has anyone come up with a way to extract the information in the Links panel?

      I would love to be able to get a list of all links, the page number they are on and scaling percentages.
        • 1. Re: Extracting info from Links panel
          Level 1
          It is somewhere between easy and trivial depending on your experience.

          It also matters which version of InDesign you're using and what scripting language you had in mind.

          Dave
          • 2. Re: Extracting info from Links panel
            Peter Kahrel Adobe Community Professional & MVP
            Kristi,

            A script was posted a while ago that may work for you. See here: http://www.adobeforums.com/webx/.3c063998/0

            Peter
            • 3. Re: Extracting info from Links panel
              GilsonAtlantic Level 1
              Peter,
              The script at the link helped a lot. I took out the info that I didn't need for the coordinates but is it possible to add a page number to help identify the link?

              f = new File ('~/coordinates.txt');
              f.open ('w');

              g = app.activeDocument.allGraphics;
              for (i = 0; i < g.length; i++)
              {
              data = File(g[i].itemLink.filePath).name + '\t';
              data += g[i].itemLink.parent.absoluteHorizontalScale + ',';
              data += g[i].itemLink.parent.absoluteVerticalScale;
              f.writeln (data)
              }

              f.close();
              • 4. Re: Extracting info from Links panel
                Peter Kahrel Adobe Community Professional & MVP
                an itemLink's greatgrandparent is a page:

                f = new File ('~/coordinates.txt');
                
                f.open ('w');

                g = app.activeDocument.allGraphics;
                for (i = 0; i < g.length; i++)
                   {
                   data = File (g[i].itemLink.filePath).name + '\t';
                   data += g[i].itemLink.parent.absoluteHorizontalScale + ',';
                   data += g[i].itemLink.parent.absoluteVerticalScale + '\t';
                   data += g[i].itemLink.parent.parent.parent.name;
                   f.writeln (data)
                   }

                f.close();


                Peter
                • 5. Re: Extracting info from Links panel
                  GilsonAtlantic Level 1
                  Thanks for all your help Peter. I really appreciate it.

                  The line for the page number worked perfectly...until I tried it on a file containing anchored graphics. On the files containing any anchored graphics, an error message popped up: Error 55. Object does not support the property or method 'name.'

                  Kris
                  • 6. Re: Extracting info from Links panel
                    Peter Kahrel Adobe Community Professional & MVP
                    Yes, I should have warned you that this was a quicky that doesn't do any (error) checking. Graphics in tables are a problem, too. Hold on a bit.

                    Peter
                    • 7. Re: Extracting info from Links panel
                      Peter Kahrel Adobe Community Professional & MVP
                      Kris,

                      Here's the adapted script. I shamelessly copied a routine posted by Harbs (see http://www.adobeforums.com/webx/.59b77ee3/6) so that you get a link's page number no matter where it is.

                      Peter

                      f = new File ('~/coordinates.txt');
                      
                      f.open ('w');

                      g = app.activeDocument.allGraphics;
                      for (i = 0; i < g.length; i++)
                         {
                         data = File (g[i].itemLink.filePath).name + '\t';
                         data += g[i].itemLink.parent.absoluteHorizontalScale + ',';
                         data += g[i].itemLink.parent.absoluteVerticalScale + '\t';
                         data += FindWhere (g[i].itemLink).name;
                         f.writeln (data)
                         }

                      f.close();

                      function FindWhere (theObj,where)
                         {
                         var err;
                         if(where==undefined){where=Page}
                         if (theObj.hasOwnProperty("baseline"))
                            {
                            try{theObj = theObj.parentTextFrames[0];}
                               catch(err){}
                            }
                         while (theObj != undefined) {
                            var whatIsIt = theObj.constructor;
                            switch (whatIsIt) {
                               case where : return theObj;
                               case Note:
                               case Footnote: theObj = theObj.storyOffset;break;
                               case Character: theObj = theObj.parentTextFrames[0]; break;
                               case Cell: theObj = theObj.insertionPoints[0].parentTextFrames[0]; break;
                               case Application: return null;
                               }
                            if (theObj == undefined) return null;
                            theObj = theObj.parent;
                            }
                         return null;
                         }
                      • 8. Re: Extracting info from Links panel
                        GilsonAtlantic Level 1
                        Peter,
                        This worked like a charm. Thank you!

                        Kris
                        • 9. Re: Extracting info from Links panel
                          Harbs. Level 6
                          Hi Peter,

                          I've reworked that function to make it more complete.

                          Here's my current version...



                          var FindWhere = function (obj, where){
                            var kAppVersion = parseFloat(app.version);
                            var getTextContainer = function (s){
                              if(kAppVersion<5){return s.textFrames[-1]}else{return s.textContainers[s.textContainers.length-1]}
                              }
                            var getobj = function (fm){//returns the parent text frame, or the last one of the parent story
                              if(fm != undefined){return fm;}else{return getTextContainer(obj.parentStory);}
                              }
                            var getobj_ptf  = function (obj){//get the parent text frame or return the original object (necessary for Notes)
                              try{ return obj.parentTextFrames[0]}catch(e){return obj}
                              }
                            var getobj_cell = function (fm){//returns the parent text frame, or the last one of the parnet story -- for cells
                              if(fm != undefined){return fm;}else{return getTextContainer(obj.insertionPoints[0].parentStory);}
                              }
                            var getnote_tf = function (note){//gets the note location for both footnotes and notes in all versions...
                              if(kAppVersion<5){
                                if(note.hasOwnProperty("footnoteTextFrame")){var parentFrame = note.footnoteTextFrame}//no good for overset...
                                else{var parentFrame = note.parentTextFrame}
                                if(parentFrame){return parentFrame}
                                else{return note.parent}
                                }
                              else{return note.storyOffset}
                              }
                            var e;
                            if(!obj){return null}
                            if(where == undefined){var where = Page;}
                            if(obj.hasOwnProperty("baseline")){obj = getobj(getobj_ptf (obj))}
                            while(obj){
                              switch(obj.constructor){
                                case where: return obj;
                                case Story: obj = getTextContainer(obj);break;
                                case Character: obj = getobj(getobj_ptf (obj));break;
                                case Cell: obj = getobj_cell(getobj_ptf(obj.insertionPoints[0]));break;
                                case Note:
                                case Footnote: obj = getnote_tf(obj);break;
                                case Application: return null;
                                }
                              if (!obj) return null;
                              obj = obj.parent;
                              }
                            return null;
                            }
                          • 11. Re: Extracting info from Links panel
                            Kasyan Servetsky Level 5
                            Here is my function that finds the page name the link is on:


                            #target indesign
                            myDoc = app.activeDocument;
                            myLink = myDoc.links[0];
                            myMessage = whereIsTheLink(myLink);
                            if (!isNaN(parseInt(myMessage))){
                               myMessage = 'page ' + myMessage;
                            }
                            alert("My link is on " + myMessage);

                            function whereIsTheLink(theLink){
                               while (theLink.constructor.name != 'Application') {
                                  if (theLink instanceof Page) {
                                     var myPageName = theLink.name;
                                     return myPageName;
                                  }
                                  if (theLink instanceof Character) {
                                     var thePage = whereIsTheLink(theLink.parentTextFrames[0]);
                                     if (thePage != undefined) return  thePage;
                                  }
                               theLink = theLink.parent;
                               myHierarchy += theLink.constructor.name + '|';
                               }
                             
                               if (myHierarchy.lastIndexOf('|Page|MasterSpread|Document|Application|') != -1)
                                  {
                                  return 'master page';
                                  }
                               else if (myHierarchy.lastIndexOf('|MasterSpread|Document|Application|') != -1)
                                  {
                                  return 'pasteboard of master page';
                                  }
                               else if (myHierarchy.lastIndexOf('|Spread|Document|Application|') != -1)
                                  {
                                  return 'pasteboard';
                                  }
                            }
                            • 12. Re: Extracting info from Links panel
                              Peter Kahrel Adobe Community Professional & MVP
                              Harbs,

                              Given "var FindWhere = function (obj, where)", what's the second parameter you call FindWhere with? A page (optionally)? Later on in the function you have "if(where == undefined){var where = Page;}", so that if you call FindWhere with just one parameter (any object), the script asserts Page. Why do you use this approach?

                              Peter
                              • 13. Re: Extracting info from Links panel
                                Harbs. Level 6
                                Peter Kahrel wrote:
                                > what's the second parameter you call FindWhere with?

                                Anything! For "Page" I leave it blank (hence the "if where ==
                                undefined"). I use it for: Spread, MasterSpread, TextFrame, Group, etc...

                                Very, very useful animal!

                                --
                                Harbs
                                http://www.in-tools.com
                                • 14. Re: Extracting info from Links panel
                                  Peter Kahrel Adobe Community Professional & MVP
                                  Ah, thanks.

                                  Peter