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
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
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
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
Copy link to clipboard
Copied
This is awesome! Works fine for me.
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.
Copy link to clipboard
Copied
I see lots of issues in your code, some of those should ultimately address your problem as well.
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
Copy link to clipboard
Copied
Hi manan,
I need to include this code after push the graphics name?
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
Copy link to clipboard
Copied
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)
linkUpadte(pgCol)