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

Limit script to specific layer

Community Beginner ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Hi, 

is it possible to limit a script to a specific layer in an InDesign document? I have a script that changes all object links in the entire document. But now I'd like to limit it to change the object links only in one selected layer. 

 

Many thanks in advance for any help! 

TOPICS
Scripting

Views

578

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 ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Sure, though it would be helpful to see the script. Rudimentarily (sorry on mobile):

 

var allLayerGraphics = app.activeDocument.layers.itemByName("layerName").allGraphics;

var aLink;

for (var i = 0; i < allLayerGraphics.length; i++) {

    try { 

        aLink = allLayerGraphics[i].itemLink;

        //Do stuff

     } catch(e) {}

}

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 Beginner ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Thanks for the swift response! 

 

I am currently using the script from Kasyan. 

Restore broken links after server migration in InDesign (ho.ua)

 

The objects I'd like to relink are not graphics but text frames that are linked to InCopy text files. This basically works the same way as for graphics, but may need a differen call than "allGraphics". Would it be "allTextFrames" instead? 

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 ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Hi juliaa87521193,

no, there is no allTextFrames array in ExtendScript.

If you are looking for text frames you could go through the allPageItems array of a layer and check if an individual item is a text frame. I'm not very much familiar with InCopy workflows, but I think, you are not after text frames but after stories that are part of an InCopy workflow.

 

If you are looking into object Story in DOM documentation there is property storyTitle, the discription says:

"Title for this InCopy story." No idea if every InCopy related story has a story title that is not an empty string. And no idea if the value of storyTitle is reset to an empty string in the moment the story is not part of an InCopy workflow anymore.

 

Maybe it would help to read out the inCopyExportOptions of all stories in a document?

And if an InCopy related story is found go through the textContainers array of that story to check if a given text frame's itemLayer is the one you are looking for?

 

Regards,

Uwe Laubender

( ACP )

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 Beginner ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

LATEST

Thanks Uwe,

 

I got some help from Kasyan, the guy writing the script I linked above. He came up with the following solution, which goes in a similar direction as you suggested I guess... However, before running the script you have to activate/select the layer in InDesign that shall be processed. That works well for me. So I can say that the problem is solved for me. 

 

var gDoc = app.activeDocument;
var gLinks = gDoc.links;
var gLayer = gDoc.activeLayer;

for (var i = gLinks.length-1; i >= 0 ; i--) {
	var currentLink = gLinks[i];
	var thisLayer = currentLink.parent.textContainers[0].itemLayer;
	
	if (currentLink.linkType == "InCopyMarkup" && thisLayer == gLayer) { // skip if not on the specific layer
		var oldPath = currentLink.filePath;
		// Doing stuff
	}
}

 

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