Skip to main content
Participant
February 9, 2009
Question

Extracting info from Links panel

  • February 9, 2009
  • 13 replies
  • 977 views
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.
This topic has been closed for replies.

13 replies

Peter Kahrel
Community Expert
Community Expert
February 12, 2009
Ah, thanks.

Peter
Peter Kahrel
Community Expert
Community Expert
February 12, 2009
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
Harbs.
Legend
February 12, 2009
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
Kasyan Servetsky
Legend
February 12, 2009
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';
}
}
Peter Kahrel
Community Expert
Community Expert
February 11, 2009
Thanks, Harbs.
Harbs.
Legend
February 11, 2009
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;
}
Participant
February 10, 2009
Peter,
This worked like a charm. Thank you!

Kris
Peter Kahrel
Community Expert
Community Expert
February 10, 2009
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.itemLink.filePath).name + '\t';
data += g.itemLink.parent.absoluteHorizontalScale + ',';
data += g.itemLink.parent.absoluteVerticalScale + '\t';
data += FindWhere (g.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;
}
Peter Kahrel
Community Expert
Community Expert
February 10, 2009
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
Participant
February 10, 2009
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
Peter Kahrel
Community Expert
Community Expert
February 9, 2009
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.itemLink.filePath).name + '\t';
data += g.itemLink.parent.absoluteHorizontalScale + ',';
data += g.itemLink.parent.absoluteVerticalScale + '\t';
data += g.itemLink.parent.parent.parent.name;
f.writeln (data)
}

f.close();


Peter