🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
15 messages
15 total messages Started by Kristi_Sunberg Mon, 09 Feb 2009 15:19
Extracting info from Links panel
#1306
Author: Kristi_Sunberg
Date: Mon, 09 Feb 2009 15:19
3 lines
720 bytes
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.
Re: Extracting info from Links panel
#1307
Author: Dave_Saunders
Date: Mon, 09 Feb 2009 15:28
5 lines
779 bytes
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
Re: Extracting info from Links panel
#1308
Author: Peter Kahrel
Date: Mon, 09 Feb 2009 15:36
5 lines
808 bytes
Kristi,

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

Peter
Re: Extracting info from Links panel
#1322
Author: Kristi_Sunberg
Date: Mon, 09 Feb 2009 21:23
10 lines
1091 bytes
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();
Re: Extracting info from Links panel
#1324
Author: Peter Kahrel
Date: Mon, 09 Feb 2009 22:34
22 lines
1082 bytes
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
Re: Extracting info from Links panel
#1458
Author: Kristi_Sunberg
Date: Tue, 10 Feb 2009 16:02
5 lines
896 bytes
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
Re: Extracting info from Links panel
#1459
Author: Peter Kahrel
Date: Tue, 10 Feb 2009 16:53
3 lines
764 bytes
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
Re: Extracting info from Links panel
#1467
Author: Peter Kahrel
Date: Tue, 10 Feb 2009 20:16
47 lines
2046 bytes
Kris,

Here's the adapted script. I shamelessly copied a routine poted 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.parent.parent.parent).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; 
   }
Re: Extracting info from Links panel
#1469
Author: Kristi_Sunberg
Date: Tue, 10 Feb 2009 21:04
4 lines
683 bytes
Peter,
This worked like a charm. Thank you!

Kris
Re: Extracting info from Links panel
#1488
Author: Harbs
Date: Wed, 11 Feb 2009 11:19
52 lines
2613 bytes
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; 
  } 
Re: Extracting info from Links panel
#1492
Author: Peter Kahrel
Date: Wed, 11 Feb 2009 13:11
1 lines
608 bytes
Thanks, Harbs.
Re: Extracting info from Links panel
#1374
Author: Kasyan_Servetsky
Date: Thu, 12 Feb 2009 08:44
40 lines
1754 bytes
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';
      }
}
Re: Extracting info from Links panel
#1376
Author: Peter Kahrel
Date: Thu, 12 Feb 2009 09:46
5 lines
936 bytes
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
Re: Extracting info from Links panel
#1385
Author: Harbs
Date: Thu, 12 Feb 2009 14:43
11 lines
963 bytes
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
Re: Extracting info from Links panel
#1386
Author: Peter Kahrel
Date: Thu, 12 Feb 2009 16:03
3 lines
615 bytes
Ah, thanks.

Peter
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads