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

Indesign Script to find the used link names in each page of active document

Participant ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

Hi Everyone,

Im new to scripting. Is there any script to find the used link names in the each pages of the active document.

This is my code

function myLinks(){
UsedPagesLinks = [];
var mypages = app.activeDocument.spreads;
if(mypages.length>0){
for(var b=0;b<mypages.length;b++){
var myPageItems = mypages[b].allGraphics;
alert(myPageItems.name)
for(var c=0;c<myPageItems.length;c++){
if(myPageItems[c].parentPage != null){
if (myPageItems[c].itemLayer.visible == true && myPageItems[c].visible == true){
UsedPagesLinks.push(myPageItems[c].name);
// alert(UsedPagesLinks)
}
}
}
}
}


}
myLinks()
TOPICS
Scripting

Views

518

Translate

Translate

Report

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 ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

Hi Raghav, you did not tell what issues are you facing in the code you posted? Tell us your problem so that we can point to the specific fix that you can apply.

-Manan

Votes

Translate

Translate

Report

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 ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

Thanks Manan!

Im trying to collect the each link names used in the pages of the active document and insert into the slug of the each pages

Votes

Translate

Translate

Report

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 ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

Try the following code

var pg = app.documents[0].allGraphics
var pgCol = {}
for(var i = 0; i < pg.length; i++)
{
	if(pg[i].parentPage != null)
	{
		if(pgCol[pg[i].parentPage.name] == undefined)
			pgCol[pg[i].parentPage.name] = []
		pgCol[pg[i].parentPage.name].push(pg[i].itemLink.name)
	}
}

It will fill the pgCol object with the properties that have name as the pagename that contains placed objects. And each property will in turn be an array containing the name of the links placed on that page. You can use this object to create your slug area

-Manan

Votes

Translate

Translate

Report

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 ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

This is awesome! Works fine for me.

 

Votes

Translate

Translate

Report

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 ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

Hi Manan,

I have wrote the below code pull the used links in the active pages and put in the active page slug table, but the script push the links from the active page but put the last linked name on every page of slug. Let me know what is the issue in my code.

myLinks(app.activeDocument)
function myLinks(doc){
var pg = doc.allGraphics
var pgCol = {}
var myFindLinks = []
for(var i = 0; i < pg.length; i++)
{
if(pg[i].parentPage != null)
{
if(pgCol[pg[i].parentPage.name] == undefined){
pgCol[pg[i].parentPage.name] = []
pgCol[pg[i].parentPage.name].push(pg[i].itemLink.name)
}
}
usedLinks = pgCol[pg[i].parentPage.name]
alert(usedLinks)
linkUpadte(usedLinks)
}
}

function linkUpadte(Links){
var myPages = app.activeDocument.spreads;
if(myPages.length>0){
for(var i=0; i<myPages.length; i++){
var pasteBoardtable = myPages[i].allPageItems;
for(var a=0;a<pasteBoardtable.length;a++){
if(pasteBoardtable[a].parentPage == null){
if(pasteBoardtable[a].constructor.name == "TextFrame"){
if(pasteBoardtable[a].tables.length > 0){
for(var b=0;b<pasteBoardtable[a].tables[0].cells.length;b++){
if(pasteBoardtable[a].tables[0].cells[b].contents.match(/LINKED IMAGES:/)){
if(pasteBoardtable[a].tables[0].cells[b+3].paragraphs.length>0){
pasteBoardtable[a].tables[0].cells[b+3].paragraphs[0].select();
pasteBoardtable[a].tables[0].cells[b+3].paragraphs[-1].select(SelectionOptions.addTo);
app.selection[0].remove();
}
pasteBoardtable[a].tables[0].cells[b+3].insertionPoints[0].contents = "Link Names: \r" + Links;
}
}
}
}
}
}
}
}
}

Votes

Translate

Translate

Report

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 ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

I see lots of issues in your code, some of those should ultimately address your problem as well.

  • In the statement usedLinks = pgCol[pg[i].parentPage.name] you are using variable i as the index but the value of i after exiting the loop would be something that will cause pg[i] to point to a non existent object. So this statement for me is wrong and might even crash
  • You call the method linkUpadte once with a single argument and use that value to fill in the table on each spread, so any table you create would have the same value and that seems to be the problem you are having.

For me, the ideal solution would be calling the linkUpadte method with pgCol as an argument. Run for each loop over pgCol, this will iterate over each page name, get the corresponding page from the name and then the value of this will give you the name array of the links that you need to place. Something like the following

function linkUpdate(pgCol)
{
  for(var n in pgCol)
  {
    var pageName = n
    var pageObj = app.documents[0].pages.itemByName(pageName)
    var linksonPage = pgCol[n] //This is an array of all the links on the page with name pageName
    //Do what you need with the list now
  }
}

-Manan

 

Votes

Translate

Translate

Report

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 ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

Hi manan,

I need to include this code after push the graphics name?

Votes

Translate

Translate

Report

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 ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

Im Confused Where to include this code in my script. Will u help me out? My output is reflected in slug table of each page

 

Votes

Translate

Translate

Report

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 ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

LATEST

I don't understand the source of confusion. I already explained everything. So, you added the following three lines to my previous code snippet, as follows.

usedLinks = pgCol[pg[i].parentPage.name]
alert(usedLinks)
linkUpadte(usedLinks)
Replace them with just a single line to call the method i.e.
linkUpadte(pgCol)
After this, change the definition of the method, as I mentioned, and add the relevant code for populating the slug table.
 
-Manan

Votes

Translate

Translate

Report

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