Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Extracting info from Links panel

New Here ,
Feb 09, 2009 Feb 09, 2009
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.
TOPICS
Scripting
942
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 09, 2009 Feb 09, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2009 Feb 09, 2009
Kristi,

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

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 09, 2009 Feb 09, 2009
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.itemLink.filePath).name + '\t';
data += g.itemLink.parent.absoluteHorizontalScale + ',';
data += g.itemLink.parent.absoluteVerticalScale;
f.writeln (data)
}

f.close();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2009 Feb 09, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 10, 2009 Feb 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 10, 2009 Feb 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 10, 2009 Feb 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;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 10, 2009 Feb 10, 2009
Peter,
This worked like a charm. Thank you!

Kris
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 11, 2009 Feb 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;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2009 Feb 11, 2009
Thanks, Harbs.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 12, 2009 Feb 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';
}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2009 Feb 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 12, 2009 Feb 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2009 Feb 12, 2009
LATEST
Ah, thanks.

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines