Can there be scripts that perform multiple operations at once?

Explorer ,
Sep 13, 2020

Copy link to clipboard

Copied

Are you like this? After importing the text, first apply the "body" paragraph style (for example:mybody) created by yourself, and then apply the "none" character style. Sometimes we need to perform "clear style first".
We always repeat operations, can we use a script to automatically complete it at once.

Similarly, for tables,
We first need to set the minimum row height,
Then set the cell style to none,
Then apply the table style you created (for example: mytable)
Finally, you also need to perform "Clear Style Priority".

Maybe we also need to set the first row as the header
This should also be done automatically once with a script.

 

Hope the master can help solve this problem~

thank you very much!

TOPICS
Activation billing and install, Bug, How to, Scripting, Server developers

Views

211

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

1 Correct Answer

Adobe Community Professional , Oct 05, 2020
Sunil Yadav Adobe Community Professional , Oct 05, 2020
Sorry for my late response. I understand from your need. You can try this code: var myDoc = app.documents[0]; /// This is for paragraphs if(myDoc.paragraphStyles.item('body').isValid){ myDoc.stories.everyItem().paragraphs.everyItem().applyParagraphStyle(myDoc.paragraphStyles.item('body'), true); } myDoc.stories.everyItem().characters.everyItem().applyCharacterStyle(myDoc.characterStyles[0]); //================ // This is for table var selectionIsInTable = false; var myTable = null; try{ ...

Likes

Translate

Translate
Jump to answer Jump to answer
Participant ,
Sep 14, 2020

Copy link to clipboard

Copied

you can use doscript:

app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'working name')

function main(){
your code here
}

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Sep 14, 2020

Copy link to clipboard

Copied

I don’t understand, can you be more specific?

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Sep 14, 2020

Copy link to clipboard

Copied

You can try something like this:

var myDoc = app.documents[0];
/// This is for paragraphs
if(myDoc.paragraphStyles.item('body').isValid){
    myDoc.stories.everyItem().paragraphs.everyItem().applyParagraphStyle(myDoc.paragraphStyles.item('body'), true);
    }
myDoc.stories.everyItem().characters.everyItem().applyCharacterStyle(myDoc.characterStyles[0]);
//================
// This is for table
var myStories = app.documents[0].stories.everyItem();
var done = true;
if(myStories.tables.length > 0) done = false;
while(!done){
    myStories.tables.everyItem().rows.everyItem().autoGrow = true;
    myStories.tables.everyItem().cells.everyItem().autoGrow = true;
    myStories.tables.everyItem().cells.everyItem().appliedCellStyle = app.documents[0].cellStyles[0];
    if(myDoc.tableStyles.item('myTable').isValid){
        myStories.tables.everyItem().appliedTableStyle = myDoc.tableStyles.item('myTable');
        }
    myStories.tables.everyItem().headerRowCount = 1;
    if(myStories.tables.everyItem().cells.everyItem().tables.length > 0){
        myStories = myStories.tables.everyItem().cells.everyItem();
        }
    else{
        done = true;
        }
    }
//================

Best

Sunil

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Sep 17, 2020

Copy link to clipboard

Copied

Thank you very much. It works.

But it changed all the tables, did not clear the priority option, and added a blank row

--------------------

The word table for the test is here (21 day validity) 

 

Below is the operation

tab-pic.jpg

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Sep 17, 2020

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Sep 17, 2020

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Sep 18, 2020

Copy link to clipboard

Copied

Try this now:

var myDoc = app.documents[0];
/// This is for paragraphs
if(myDoc.paragraphStyles.item('body').isValid){
    myDoc.stories.everyItem().paragraphs.everyItem().applyParagraphStyle(myDoc.paragraphStyles.item('body'), true);
    }
myDoc.stories.everyItem().characters.everyItem().applyCharacterStyle(myDoc.characterStyles[0]);
//================
// This is for table
app.selection[0].rows.everyItem().autoGrow = true;
app.selection[0].cells.everyItem().autoGrow = true;
app.selection[0].rows[0].rowType = RowTypes.HEADER_ROW;
app.selection[0].cells.everyItem().appliedCellStyle = app.documents[0].cellStyles[0];
if(myDoc.tableStyles.item('myTable').isValid){
    app.selection[0].appliedTableStyle = myDoc.tableStyles.item('myTable');
    }
app.selection[0].rows.everyItem().height = "8mm";

Best

Sunil

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Sep 19, 2020

Copy link to clipboard

Copied

Hello Sunil_Yadav1~

Thank you so much!

I tried it, but it didn’t work. Help me to see it again.

 

For paragraphs:
    It works, and uses the body style, but there is no clear preference.

For table
   Prompt the following error:

   Object does not support the property or method'rows'
   cells are also not supported

tab-wrong.jpg

 

 

 

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Sep 19, 2020

Copy link to clipboard

Copied

With the table, you need to ensure you have the entire table selected. You can add this line to check after the comments for the start of the table methods: 

if (!app.selection[0] instanceof Table) {
    alert("you must select a table!")
    exit();
}

  

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Sep 20, 2020

Copy link to clipboard

Copied

You don’t have to select the entire table. I have seen some scripts that only need the cursor in the table to execute on the entire table.

But I don’t know how to do it

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Sep 20, 2020

Copy link to clipboard

Copied

The way Sunil wrote the script it requires you to select the entire table. There are other ways to get at a table with the cursor being in the table, but it involves more coding to get right. 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Oct 05, 2020

Copy link to clipboard

Copied

Sorry for my late response.

I understand from your need.

You can try this code:

var myDoc = app.documents[0];
/// This is for paragraphs
if(myDoc.paragraphStyles.item('body').isValid){
    myDoc.stories.everyItem().paragraphs.everyItem().applyParagraphStyle(myDoc.paragraphStyles.item('body'), true);
    }
myDoc.stories.everyItem().characters.everyItem().applyCharacterStyle(myDoc.characterStyles[0]);
//================
// This is for table
var selectionIsInTable = false;
var myTable = null;
try{
    if(app.selection[0].parent.constructor.name == "Cell"){
        selectionIsInTable = true;
        myTable = app.selection[0].parent.parent;
        }
    else if(app.selection[0].constructor.name == "Cell"){
        selectionIsInTable = true;
        myTable = app.selection[0].parent;
        }
    else if(app.selection[0].constructor.name == "Table"){
        selectionIsInTable = true;
        myTable = app.selection[0];
        }
    }
catch(e){
    selectionIsInTable = false;
    }
if(selectionIsInTable && myTable != null && myTable != undefined){
    myTable.rows.everyItem().autoGrow = true;
    myTable.cells.everyItem().autoGrow = true;
    myTable.rows[0].rowType = RowTypes.HEADER_ROW;
    myTable.cells.everyItem().appliedCellStyle = app.documents[0].cellStyles[0];
    if(myDoc.tableStyles.item('myTable').isValid){
        myTable.appliedTableStyle = myDoc.tableStyles.item('myTable');
        }
    myTable.rows.everyItem().height = "8mm";
    }

Best

Sunil 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
喜狼_edny AUTHOR LATEST
Explorer ,
Jan 25, 2021

Copy link to clipboard

Copied

Sorry, there is still a problem with this script:

Yes, it works, but it's too slow for text.

 

The table part still has no clear priority (paragraph style, character style, table style and cell style should be cleared)

 

Paragraph style, character style, table style and cell style should be cleaned up.

To put it simply: clear and restore paragraph, character, table and cell styles to none

no.jpgno2.jpg

Hello

Sorry, I haven't seen it for a long time.

This script corresponds to paragraph style. It runs too slowly. And there is no clear priority.

 

Table scripts also have no preference for clearing character styles and paragraph styles

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Sep 24, 2020

Copy link to clipboard

Copied

This script takes a long time to run... a bit inefficient

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more