Skip to main content
Maiane Gabriele
Inspiring
January 2, 2020
Answered

How to create a script to clear overrides just in one layer?

  • January 2, 2020
  • 1 reply
  • 1307 views

Hello, people!

Hope you can help me. 😛

 

I'm trying to edit a script I already use to work in just one layer.

The working script is like this one:

var myOverrideType = OverrideType.ALL;
var allStories = app.activeDocument.stories.everyItem();

try{
   allStories.clearOverrides(myOverrideType);
}
catch (e) {}

 It works just fine. It clears the overrides in all stories in my document.

 

Right now, I want to change it to clear the overrides just at the stories that are inside a specific layer, since this way I have more control under what overrides I'm clearing.

Here is what I tried and didn't work:

var myOverrideType = OverrideType.ALL;
var myLayer = app.activeDocument.layers.item("text");

try{
   myLayer.stories.everyItem().clearOverrides(myOverrideType);
}
catch (e) {}

 It should had took my layer named "text" and clear all the overrides inside the stories that are inside it.

 

Is there someone who can help me? What am I doing wrong?

I've alredy tried to look for anwsers everywhere.

 

Thank you so much in advance. 🙂

This topic has been closed for replies.
Correct answer brian_p_dts

Layer does not provide access to the Stories object: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Layer.html

 

Best thing I can think of at the moment is to get the parent stories of all Text Frames on the layer, and clear those overrides. You'll have to loop through them, I think: 

 

 

 

var storiesOnLayer = app.activeDocument.layers.itemByName("text").textFrames.everyItem().parentStory;
for (var i = 0; i < storiesOnLayer.length; i++) {
    storiesOnLayer[i].clearOverrides(OverrideType.ALL);
}

 

 

1 reply

brian_p_dts
Community Expert
brian_p_dtsCommunity ExpertCorrect answer
Community Expert
January 2, 2020

Layer does not provide access to the Stories object: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Layer.html

 

Best thing I can think of at the moment is to get the parent stories of all Text Frames on the layer, and clear those overrides. You'll have to loop through them, I think: 

 

 

 

var storiesOnLayer = app.activeDocument.layers.itemByName("text").textFrames.everyItem().parentStory;
for (var i = 0; i < storiesOnLayer.length; i++) {
    storiesOnLayer[i].clearOverrides(OverrideType.ALL);
}

 

 

Maiane Gabriele
Inspiring
January 3, 2020

Thank you so much! 🙂

It worked perfectly.