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

Clearing the “clearOverrides(Priority Options?)” code does not work

Guide ,
Dec 31, 2024 Dec 31, 2024


I've tried some codes on the internet and they all failed. There doesn't seem to be any online for individual tables.

A. I am trying to clear the table style “Preferred Options”.
B, cell styles “preferred options”, “non-custom style properties”.
C. Paragraph styles “Preferred Options”.
D. Apply character style “none”.

 

For example, this sentence wants to clear the cell style priority.

 

myTable.everyItem().cells.everyItem().paragraphs.everyItem().clearOverrides(myOverrideType);

 

I have a feeling it's the front of clearOverrides that's wrong.
Someone would like to point it out.

 

Here's a script that's a little complicated.
Is there anything that can be done in a couple of sentences?

https://raw.githubusercontent.com/grefel/clearOverrides/refs/heads/master/ClearStyleOverrides.jsx

 

I added these two lines and it seemed to work, but the “undefined style attribute” was not cleared.

 

myTable.clearTableStyleOverrides();
myTable.cells.everyItem().clearCellStyleOverrides();

 

 

1228.jpg

TOPICS
Bug , How to , Performance , Scripting , Type
792
Translate
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

correct answers 1 Correct answer

New Here , Jan 01, 2025 Jan 01, 2025

Hello,

 

Your goal of clearing table, cell, and paragraph styles and applying the "None" character style efficiently, here's a streamlined script in Adobe InDesign scripting (JavaScript): 

// Clear table style overrides
myTable.clearTableStyleOverrides();

// Clear cell style overrides
myTable.cells.everyItem().clearCellStyleOverrides();

// Clear paragraph style overrides
myTable.cells.everyItem().paragraphs.everyItem().clearOverrides();

// Apply "None" character style
var noneCharStyle = myDocument.charac

...
Translate
Mentor ,
Dec 31, 2024 Dec 31, 2024

Not sure whether that solves your problem, but clearCellStyleOverrides() has an optional argument.

DirkBecker_0-1735710452756.png

 

Translate
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
Guide ,
Dec 31, 2024 Dec 31, 2024

How do I use it?

myTable.cells.everyItem().clearCellStyleOverrides(optional);
 
tip-off error:
optionalisundefined
optionalisundefined
 
Translate
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
Mentor ,
Dec 31, 2024 Dec 31, 2024

The parameter is a boolean. Use true or false.

That (Optional) means you can leave the parameter out, as you initially did.

Unfortunately the description does not tell whether true or false is the default.

Translate
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
Guide ,
Dec 31, 2024 Dec 31, 2024

useless。

I've tried all of these below, and I suspect that the description of the position in front of clearOverrides is wrong。

try{
myTable.clearTableStyleOverrides();
myTable.cells.everyItem().clearCellStyleOverrides();
myTable.rows.everyItem().cells.everyItem().clearOverrides(OverrideType.ALL);
myTable.everyItem().clearTableStyleOverrides(OverrideType.ALL);
myTable.everyItem().cells.everyItem().clearCellStyleOverrides(OverrideType.ALL);
myTable.texts[0].clearOverrides(OverrideType.ALL);

}
catch(e){};

 

Translate
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
Mentor ,
Jan 01, 2025 Jan 01, 2025

you don't initialize myTable.

Also you are passing OverrideType.ALL to clearCellStyleOverrides() instead of true or false.

Besides the separate try-catch that you eliminated in the other thread still make sense, as you write it InDesign will only execute until the first error line and skip the others.

Without doing anything about the exception e from the catch(e), you won't even know where the script fails.

Translate
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
Guide ,
Jan 01, 2025 Jan 01, 2025

The myTable is initialized on the front side.

 

Translate
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
New Here ,
Jan 01, 2025 Jan 01, 2025

Hello,

 

Your goal of clearing table, cell, and paragraph styles and applying the "None" character style efficiently, here's a streamlined script in Adobe InDesign scripting (JavaScript): 

// Clear table style overrides
myTable.clearTableStyleOverrides();

// Clear cell style overrides
myTable.cells.everyItem().clearCellStyleOverrides();

// Clear paragraph style overrides
myTable.cells.everyItem().paragraphs.everyItem().clearOverrides();

// Apply "None" character style
var noneCharStyle = myDocument.characterStyles.itemByName("[None]");
myTable.cells.everyItem().paragraphs.everyItem().appliedCharacterStyle = noneCharStyle;

Clear Table Style Overrides: myTable.clearTableStyleOverrides(); removes table-level overrides.
Clear Cell Style Overrides: myTable.cells.everyItem().clearCellStyleOverrides(); clears all cell-level styles.
Clear Paragraph Style Overrides: myTable.cells.everyItem().paragraphs.everyItem().clearOverrides(); removes any overrides applied to paragraphs in the table.
Apply "None" Character Style: This ensures no character styles are applied, setting the text to the default "[None]" style.

Replace myTable with your specific table reference in the script.
Ensure your document is correctly referenced with myDocument.
"[None]" is the default character style name in InDesign, so this line works universally.

If "undefined style attributes" persist, ensure no conflicting custom styles are being reapplied afterward. This script should comprehensively reset all styles in a clean and efficient manner.

Translate
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
Guide ,
Jan 01, 2025 Jan 01, 2025
LATEST

Thank you very much.
This basic, universally applicable stuff is so important.
Thanks for sharing such great tips.

Translate
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