Copy link to clipboard
Copied
How should the code to clear the "Preferences" of "Character Style" and "Paragraph Style" be written?
Similarly, how do you write the code to clear the "Preferences" of "Table Style" and "Cell Format"?
These styles are imported from word, I don’t need them, they must be removed.
Thank you.
Text or paragraphs have a clearOverrides method. This would get all of the stories in the active document, and clear the texts Pargraph and Character Style overrides.
//gets all of the document’s stories and clear their overrides
var txt = app.documents[0].stories.everyItem().clearOverrides(OverrideType.ALL)
//this would clear the paragraph overrides and leave the character overrides unchanged
var txt = app.documents[0].stories.everyItem().clearOverrides(OverrideType.OverrideType.PARAGRAP
...
Copy link to clipboard
Copied
I am not sure if I understood your question well. I suppose the following objects and properties could get you what you want
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#WordRTFImportPreference.html
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#TextImportPreference.html
-Manan
Copy link to clipboard
Copied
—These styles are imported from word, I don’t need them, they must be removed.
If you want to delete imported styles, you can use the remove method. You can choose to replace with a new style with the parameter:
//gets the style to remove
var ps = app.activeDocument.paragraphStyles.itemByName("ImportedStyleName");
ps.remove("ReplacementStyle")
You could also check if a style is imported:
var ps = app.activeDocument.paragraphStyles;
for (var i = 0; i < ps.length; i++){
//Check if the style is imported
if (ps[i].imported) {
$.writeln("Imported")
//remove and replace
ps[i].remove("ReplacementStyle")
}
};
Copy link to clipboard
Copied
Hello, rob day.
I actually want to achieve: after importing my word text, apply the "mybody" paragraph style, apply the "none" character style, and clear the "priority option".
The same: after applying the script, apply the "mytab" table style, apply the "none" cell style, and clear the "preferences" of the table.
Thanks~
Copy link to clipboard
Copied
What does "priority option" mean? Do you mean you want to clear overrides from the imported text (Paragraph Styles panel>Clear Overrides)?
Copy link to clipboard
Copied
Overrides?
Maybe it’s what you said, it’s the one you need to press Alt+double click to clear.
We call it: mixed priority options。
Copy link to clipboard
Copied
Text or paragraphs have a clearOverrides method. This would get all of the stories in the active document, and clear the texts Pargraph and Character Style overrides.
//gets all of the document’s stories and clear their overrides
var txt = app.documents[0].stories.everyItem().clearOverrides(OverrideType.ALL)
//this would clear the paragraph overrides and leave the character overrides unchanged
var txt = app.documents[0].stories.everyItem().clearOverrides(OverrideType.OverrideType.PARAGRAPH_ONLY)
Copy link to clipboard
Copied
Hello~
rob day
It is "Clear Overrides".
It's a bit complicated, I don't understand it very well.
Can you write it completely for me? thank you very much!
------------------------------------
This is what I want to achieve:
after importing my text, apply the "mybody" paragraph style, apply the "none" text style, and perform "clear overrides" for "mybody".
(If it is not selected, The script will work on the entire text box. If selected, The script is useful for the current selection.)
If it is a table: After applying the script, apply the "mytab" table style and the "none" cell style. And perform "clear overrides" for "mytab",and "clear overrides" for "none" character style.
(No need to select, The script works on the table where the cursor is currently located)