Get all links from one InDesign layer only.

I’m trying to get all linked images from a certain InDesign layer only.

To get all links in an InDesign document i use

set linksTotal to every link of document 1

and if i would like to get every link with a certain status this works fine.

set linksMissing to every link of document 1 whose status = link missing

But for a new project i would like to get every link of one InDesign layer only so i thought i could use something like this

set linksWebTotal to every link of document 1 whose item layer's name is WebLayer

But it does not seem to work, neither does

set linksWebTotal to every link of (layer WebLayer of document 1)

I’m out of ideas, here is a small test script if someone would like to try it out. You will need an InDesign document with two layers and one is labeled WebLinks and both layers need to have at least one image linked to it.


set WebLayer to "WebLinks"
tell application "Adobe InDesign CC 2017"
	set linksTotal to every link of document 1
	set linksWebTotal to every link of document 1 whose item layer's name is WebLayer
end tell

set linksTotalNr to count linksTotal
set linksWebTotalNr to count linksWebTotal

display dialog "Links total = " & linksTotalNr & return & "Links 4 web = " & linksWebTotalNr

Ps. I have also tried to hide all the other layers and get the links but it does not make any difference when scripting.

Hi
Try this

 tell application id "com.adobe.InDesign"
	tell document 1
		set Links_ to page 1's every page item whose item layer's name is "WebLayer"
		select Links_
	end tell
end tell

Marc from this thread shows how to go about it:

Hi Budgie.

Same result as with my own tries, zero links found.

Edit:
Sorry, it was to early in the morning for me, it seems to work.

And it seems to work just fine like this also.

set linksWebTotal to every page item whose item layer's name is WebLayer

Seems that getting the page items is not the same as get links, so when continuing with the script where i need to get the name of the link and then relink it will not work. So i’m back to square one.

Link is only useful in the document context. You want item link.
You can do this with a whose clause, as you requested…

tell application "Adobe InDesign CS3"'s document 1 to (page items whose item layer's name is "Weblink")'s all graphics's item link

It’s easier and perhaps more efficient to target the layer directly:

tell application "Adobe InDesign CS3"'s document 1 to layer "WebLinks"'s all graphics's item link