Copy link to clipboard
Copied
-------------------------------------------------------------------------------------------
Sorry, I asked a similar question, but I didn't explain it clearly at that time.
At that time, a teacher gave the script, but the script was too slow to apply.
-------------------------------------------------------------------------------------------
After I import word text, I need to apply paragraph style (for example: Zw) and "None" character style to all text.
Here's a problem to deal with: sometimes you have to perform "clear priorities(clear preferences)".
Only in this way can the style application be effective.
The table applies the table style (for example: tab) and the none cell style.
Same problem: sometimes you have to perform table style > clear preferences; cell style > clear preferences.
Now, what I want to ask for help is: whether the above operation can be realized with one click script.
Best wishes
Try this :
//===================================
applyStyles();
//===================================
function applyStyles(){
try{
if(app.selection != null){
for(var s = 0; s < app.selection.length; s++){
var obj = app.selection[s];
if(obj.hasOwnProperty("characters")){
obj.texts[0].appliedCharacterStyle = app.documents[0].characterStyles[0];
if(app.documents[0].paragraphStyles.item("mypar").isValid)
...
Copy link to clipboard
Copied
You can clear overrides from entire document of Paragraph Styles, Character Styles, Table Styles & Cell Styles with this snippet :
//===================================
var allStories = app.documents[0].stories.everyItem();
allStories.clearOverrides(OverrideType.ALL);
allStories.tables.everyItem().clearTableStyleOverrides(true);
allStories.tables.everyItem().cells.everyItem().clearCellStyleOverrides(true);
//===================================
Best
Sunil
Copy link to clipboard
Copied
From the Object Model Viewer: Text.applyParagraphStyle (using: ParagraphStyle , clearingOverrides: Boolean )
In other words, assume you have selected some text (your script should verify that):
app.selection[0].applyParagraphStyle(pStyle, true);
where pStyle is a reference (not just the name) of an existing paragraph style. Apparently clearingOverrides defaults to true but I'm in the habit of always specifying it.
You might see examples saying something like text.appliedParagraphStyle = pStyle but that doesn't give you the option of clearing overrides at the same time. Also note, that clearingOverrides doesn't do anything about any character styles already applied. So you may want to add a line to set the appliedCharacterStyle to [None].
Hope this helps,
Bob
Copy link to clipboard
Copied
Is it possible to target the currently selected content or text frame?
How to write the paragraph style of "ZW" directly?
Best wishes
Copy link to clipboard
Copied
This below script will target on selected Text Frame or selected content to clear over rides:
//===================================
clearOverridesOnSelection();
//===================================
function clearOverridesOnSelection(){
try{
if(app.selection != null){
for(var s = 0; s < app.selection.length; s++){
var obj = app.selection[s];
if(obj instanceof TextFrame || obj.hasOwnProperty("characters")){
obj.texts[0].clearOverrides(OverrideType.ALL);
if(obj.texts[0].tables.length > 0){
obj.texts[0].tables.everyItem().clearTableStyleOverrides(true);
obj.texts[0].tables.everyItem().cells.everyItem().clearCellStyleOverrides(true);
}
}
}
}
}
catch(e){}
}
//===================================
Best
Sunil
Copy link to clipboard
Copied
The script runs and works.
The purpose of this script is to initialize the text.
If you can apply paragraph style: "mypar", the default character style is "None".
At the same time, the table style "mytab" and the default cell style "None" are applied.
The minimum row height of the table is 7.6 mm (the cell style cannot achieve the minimum row height).
It would be perfect.
Copy link to clipboard
Copied
Try this :
//===================================
applyStyles();
//===================================
function applyStyles(){
try{
if(app.selection != null){
for(var s = 0; s < app.selection.length; s++){
var obj = app.selection[s];
if(obj.hasOwnProperty("characters")){
obj.texts[0].appliedCharacterStyle = app.documents[0].characterStyles[0];
if(app.documents[0].paragraphStyles.item("mypar").isValid) obj.texts[0].appliedParagraphStyle = "mypar";
if(obj.texts[0].tables.length > 0){
if(app.documents[0].tableStyles.item("mytab").isValid) obj.texts[0].tables.everyItem().appliedTableStyle = "mytab";
obj.texts[0].tables.everyItem().cells.everyItem().appliedCellStyle = app.documents[0].cellStyles[0];
if(app.documents[0].paragraphStyles.item("mypar").isValid){
obj.texts[0].tables.everyItem().cells.everyItem().texts[0].texts[0].appliedParagraphStyle = "mypar";
}
obj.texts[0].tables.everyItem().cells.everyItem().texts[0].appliedCharacterStyle = app.documents[0].characterStyles[0];
obj.texts[0].tables.everyItem().clearTableStyleOverrides(true);
obj.texts[0].tables.everyItem().cells.everyItem().clearCellStyleOverrides(true);
}
obj.texts[0].clearOverrides(OverrideType.ALL);
}
}
}
}
catch(e){}
}
//===================================
Best
Sunil
Copy link to clipboard
Copied
Except the minimum row height of the table is not implemented.
The rest is perfect.
Thank you very much~