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

Can a paragraph style, character style, table style and cell style be applied with one click?

Enthusiast ,
Apr 08, 2021 Apr 08, 2021

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.

The example file used is here

 

CLEAR-1.jpgCLEAR-2.jpg

 

 

Best wishes

 

 

TOPICS
Bug , Feature request , How to , Import and export , Scripting

Views

531

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

correct answers 1 Correct answer

Advocate , Apr 17, 2021 Apr 17, 2021

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) 
...

Votes

Translate

Translate
Advocate ,
Apr 09, 2021 Apr 09, 2021

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

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
Engaged ,
Apr 09, 2021 Apr 09, 2021

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

 

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
Enthusiast ,
Apr 09, 2021 Apr 09, 2021

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

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
Advocate ,
Apr 15, 2021 Apr 15, 2021

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

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
Enthusiast ,
Apr 17, 2021 Apr 17, 2021

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.

 

initialization.jpg

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
Advocate ,
Apr 17, 2021 Apr 17, 2021

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

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
Enthusiast ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

LATEST

Except the minimum row height of the table is not implemented.

The rest is perfect.

Thank you very much~

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