• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Delete imported styles (Paragraph and Character Styles from MS Word) - No Preserve Formatting

New Here ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

Hello everyone,

I need to create several files in indesign using text import from MS Word. (I don't use "Show import Options", just copy and paste with "All information" marked in Preferences > clipboard handling).

 

After applying some actions in GREP, I need to delete all the styles that appeared due to import, they are indicated by indesign with an icon as shown in the image below:

 

Captura de tela 2021-11-09 140337.png


Is it possible to modify the script below to identify and delete these imported styles without keeping the formatting? Thanks in advance if anyone can help me modify it.

main();

function main(){
    var targetDoc = app.activeDocument;
    removeAllTypeStyles (targetDoc);
}

function removeAllTypeStyles (targetDoc) {

    //remove all paragraph styles
    for (var ps = targetDoc.allParagraphStyles.length - 1; ps >= 0; ps--) {

        if (targetDoc.allParagraphStyles[ps].name != "[No Paragraph Style]" && targetDoc.allParagraphStyles[ps].name != "[Basic Paragraph]") {
            targetDoc.allParagraphStyles[ps].remove (targetDoc.paragraphStyles.itemByName ("[No Paragraph Style]"));
        }

    }

    //remove all character styles
    for (var cs = targetDoc.allCharacterStyles.length - 1; cs >= 0; cs--) {

        if (targetDoc.allCharacterStyles[cs].name != "[None]") {
            targetDoc.allCharacterStyles[cs].remove (targetDoc.characterStyles.itemByName ("[None]"));
        }

    }
	
} 
TOPICS
How to , Import and export , Scripting

Views

820

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 2 Correct answers

Community Expert , Nov 09, 2021 Nov 09, 2021

Hi @Tete San, here is your modified script that removed imported type styles. Just checks the 'imported' property.

- Mark

 

 

 

 

function main() {

    var targetDoc = app.activeDocument;
    removeImportedTypeStyles(targetDoc);

    function removeImportedTypeStyles(targetDoc) {

        //remove all imported paragraph styles
        var paraStyles = targetDoc.allParagraphStyles,
            replacementParagraphStyle = targetDoc.paragraphStyles.item(0);
        for (var i = targetDoc.allParagraphSty
...

Votes

Translate

Translate
Community Expert , Nov 10, 2021 Nov 10, 2021

Hi @Tete San, sure! Here's one way:

function main() {

    // you can set this to how you want it:
    var deleteImportedStylesFromAllDocuments = true;

    // get array of every document, or just the active document
    var docs = (deleteImportedStylesFromAllDocuments == true)
        ? app.documents
        : [app.activeDocument];

    if (docs.length == 0) return;

    // remove imported styles from every document in docs
    for (var i = 0; i < docs.length; i++) {
        removeImportedTypeSt
...

Votes

Translate

Translate
Advisor ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

Hello @Tete San,

 

In Indesign if you go to File > Place > select on a Word document and show import options the below dialog will open giving you options for importing, Let us know if that helps.

Screen Shot 2021-11-09 at 3.48.59 PM.png

Regards,

Mike

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
New Here ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

Hi Mike, thanks for the reply. I already know these options. They don't work in my case as I get .doc and .docx from different versions of MS Word and different stakeholders. Imported styles become a huge mess.

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
Community Expert ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

Hi @Tete San, here is your modified script that removed imported type styles. Just checks the 'imported' property.

- Mark

 

 

 

 

function main() {

    var targetDoc = app.activeDocument;
    removeImportedTypeStyles(targetDoc);

    function removeImportedTypeStyles(targetDoc) {

        //remove all imported paragraph styles
        var paraStyles = targetDoc.allParagraphStyles,
            replacementParagraphStyle = targetDoc.paragraphStyles.item(0);
        for (var i = targetDoc.allParagraphStyles.length - 1; i >= 0; i--) {
            if (paraStyles[i].name != replacementParagraphStyle.name
                && paraStyles[i].imported == true
            ) {
                paraStyles[i].remove(replacementParagraphStyle);
            }
        }

        //remove imported character styles
        var charStyles = targetDoc.allCharacterStyles,
            replacementCharacterStyle = targetDoc.characterStyles.item(0);
        for (var i = targetDoc.allCharacterStyles.length - 1; i >= 0; i--) {
            if (
                charStyles[i].name != replacementCharacterStyle.name
                && charStyles[i].imported == true
            ) {
                charStyles[i].remove(replacementCharacterStyle);
            }
        }

    }


} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Delete Imported Type Styles');

 

 

 

 

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
New Here ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

Hi Mark, thanks for your attention, I have tested it and it's working perfectly. I also really liked the way you organized the code. Is it possible to apply this script to all documents opened in indesign as a loop?

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
Community Expert ,
Nov 10, 2021 Nov 10, 2021

Copy link to clipboard

Copied

Hi @Tete San, sure! Here's one way:

function main() {

    // you can set this to how you want it:
    var deleteImportedStylesFromAllDocuments = true;

    // get array of every document, or just the active document
    var docs = (deleteImportedStylesFromAllDocuments == true)
        ? app.documents
        : [app.activeDocument];

    if (docs.length == 0) return;

    // remove imported styles from every document in docs
    for (var i = 0; i < docs.length; i++) {
        removeImportedTypeStyles(docs[i]);
    }


    function removeImportedTypeStyles(targetDoc) {

        //remove all imported paragraph styles
        var paraStyles = targetDoc.allParagraphStyles,
            replacementParagraphStyle = targetDoc.paragraphStyles.item(0);
        for (var i = targetDoc.allParagraphStyles.length - 1; i >= 0; i--) {
            if (
                paraStyles[i].name != replacementParagraphStyle.name
                && paraStyles[i].imported == true
            ) {
                paraStyles[i].remove(replacementParagraphStyle);
            }
        }

        //remove imported character styles
        var charStyles = targetDoc.allCharacterStyles,
            replacementCharacterStyle = targetDoc.characterStyles.item(0);
        for (var i = targetDoc.allCharacterStyles.length - 1; i >= 0; i--) {
            if (
                charStyles[i].name != replacementCharacterStyle.name
                && charStyles[i].imported == true
            ) {
                charStyles[i].remove(replacementCharacterStyle);
            }
        }

    }


} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Delete Imported Type Styles');

 

- Mark

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
New Here ,
Nov 11, 2021 Nov 11, 2021

Copy link to clipboard

Copied

LATEST

Thank you so much Mark! It works perfectly, I'm already using it.

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
Community Expert ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

You can also purge styles before you import from Word; perhaps the simplest approach in the future is not to bring all that baggage into the ID document at step 1, rather than having to resort to scripts to clean it all up. šŸ™‚


ā•Ÿ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ā•¢

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
New Here ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

Hi NitroPress, yes better to purge first and not bring garbage to the document! However in my case I need the imported styles at some point because I need to see them and run GREP routines before deleting them. The annoying was really deleting them because there are many styles and many documents, which the script solves perfectly. Thanks

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