6 Replies Latest reply on Oct 5, 2016 8:33 AM by Pete Stan

    Evoke: Load Table Cells and Styles...

    Pete Stan

      Hi,

       

      Is it possible to open the dialog via scripting:

      Screen Shot 2016-09-22 at 14.51.41.png

       

      And once the Dialog is open, load custom Paragraph, Character, Table and Cell styles from the file (with user selection):

       

      Screen Shot 2016-09-22 at 14.49.32.png

       

      Apply only Body Text from selection to all [No Paragraph Style] text?

      (Note: That user can only select 'Body Text' Paragraph style once either from Folder 'AR' or 'HB')

        • 1. Re: Evoke: Load Table Cells and Styles...
          tpk1982 Level 4

          simple but effective to load table style

           

          app.menuActions.itemByID(132109).invoke();

          1 person found this helpful
          • 2. Re: Evoke: Load Table Cells and Styles...
            Pete Stan Level 1

            Thank you, this command works indeed on it's own. However when I am trying to use it with Jongsware's PrepText - nothing is happening:

             

            Here's my try:

            //Jongware's PrepText starts here
            
            if (app.activeDocument.selection[0].constructor.name != "InsertionPoint")
            {
                alert ("Cursor in "+app.activeDocument.selection[0].constructor.name+"\nPlease put the cursor into a text frame");
                exit(0);
            }
            
            var myMaximumValue = 63;
            var myProgressBarWidth = 384;
            var myIncrement = myMaximumValue/myProgressBarWidth;
            myCreateProgressPanel(myMaximumValue, myProgressBarWidth);
            
            myProgressPanel.myProgressBar.value = 0;
            myCreateProgressPanel(100, 400);
            myProgressPanel.show();
            
            for (b=0; b<2; b++)
            {
                for (i=0; i<2; i++)
                {
                    for (s=0; s<2; s++)
                    {
                        for (u=0; u<2; u++)
                        {
                        //    Don't process strikeout
                            for (k=0; k<1; k++)
                            {
                                for (c=0; c<2; c++)
                                {
                                    if (b+i+s+u+k+c)
                                    {
                                        myProgressPanel.myProgressBar.value = 32*b+16*i+8*s+4*u+2*k+c;
                                        findAttr (b, i, s, false, u, /*k*/false, c, "");
                                        if (s)
                                            findAttr (b, i, false, s, u, /*k*/false, c, "");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            myProgressPanel.hide();
            
            exit(0);
            
            function myCreateProgressPanel(myMaximumValue, myProgressBarWidth)
            {
                myProgressPanel = new Window('window', 'Prepping text');
                with(myProgressPanel)
                {
                    myProgressPanel.myProgressBar = add('progressbar', [12, 12, myProgressBarWidth, 24], 0, myMaximumValue);
                }
            }
            
            function findAttr (bold, italic, superscript, subscript, underline, strikeout, smallcaps, StyleName)
            {
                app.findTextPreferences = NothingEnum.nothing;
                app.changeTextPreferences = NothingEnum.nothing;
                app.findTextPreferences.appliedCharacterStyle = app.activeDocument.characterStyles[0];    // "[None]"
            
                app.findTextPreferences.fontStyle = "Regular";
                app.findTextPreferences.position = Position.normal;
                app.findTextPreferences.capitalization = Capitalization.normal;
                app.findTextPreferences.underline = false;
                app.findTextPreferences.strikeThru = false;
            
                if (bold)
                {
                    if (italic)
                        app.findTextPreferences.fontStyle = "Bold Italic";
                    else
                        app.findTextPreferences.fontStyle = "Bold";
                } else
                {
                    if (italic)
                        app.findTextPreferences.fontStyle = "Italic";
                }
                if (superscript)
                    app.findTextPreferences.position = Position.superscript;
            
                if (subscript)
                    app.findTextPreferences.position = Position.subscript;
            
                if (underline)
                    app.findTextPreferences.underline = true;
                if (strikeout)
                    app.findTextPreferences.strikeThru = true;
                if (smallcaps)
                    app.findTextPreferences.capitalization = Capitalization.smallCaps;
            
                foundItems = app.activeDocument.selection[0].parent.findText();
            
                if (foundItems.length > 0)
                {
                    if (StyleName == "")
                    {
                    //    Make up a name
                        if (bold)
                            StyleName = "Bold";
                        if (italic)
                        {
                            if (bold)
                                StyleName = "Bold Italic";
                            else
                                StyleName = "Italic";
                        }
                        if (superscript)
                        {
                            if (StyleName) StyleName += " + ";
                            StyleName += "Super";
                        }
                        if (subscript)
                        {
                            if (StyleName) StyleName += " + ";
                            StyleName += "Sub";
                        }
                        if (underline)
                        {
                            if (StyleName) StyleName += " + ";
                            StyleName += "Underline";
                        }
                        if (strikeout)
                        {
                            if (StyleName) StyleName += " + ";
                            StyleName += "Stkout";
                        }
                        if (smallcaps)
                        {
                            if (StyleName) StyleName += " + ";
                            StyleName += "Scaps";
                        }
                        try
                        {
                            cstyle = app.activeDocument.characterStyles.add({name:StyleName}); // , fontStyle:app.findTextPreferences.fontStyle, underline:app.findTextPreferences.underline, strikeThru:app.findTextPreferences.strikeThru, position:app.findTextPreferences.position, capitalization:app.findTextPreferences.capitalization});
                            if (bold || italic) cstyle.fontStyle = app.findTextPreferences.fontStyle;
                            if (superscript || subscript) cstyle.position = app.findTextPreferences.position;
                            if (underline) cstyle.underline = app.findTextPreferences.underline;
                            if (strikeout) cstyle.strikeThru = app.findTextPreferences.strikeThru;
                            if (smallcaps) cstyle.capitalization = app.findTextPreferences.capitalization;
                        } catch (e)
                        {
                        }
                    }
                    app.changeTextPreferences.appliedCharacterStyle = StyleName;
                    app.activeDocument.selection[0].parent.changeText (false);
                }
            }
            
            //Load Table and Cell styles
            try {
                 var loadStyles = app.menuActions.itemByID(132109).invoke();
                 }
                 catch (e) {}
            
            • 3. Re: Evoke: Load Table Cells and Styles...
              Laubender Adobe Community Professional & MVP

              Hi Pete,

              maybe you'll get some information out of the catch you implemented.

               

              catch(e){alert("Error:"+"\r"+e.message)};
              

               

              You said you tested the menu command on its own.
              What you'll get is a document open dialog where you can choose an InDesign document with the styles you want to transfer.
              It will not load anything. It's waiting for user intervention.

               

              I think you'll better use the document.importStyles() method.

              A method with three arguments:

              1. ImportFormat (e.g. table style format or cell style format)

              2. File (your InDesign file you want to import the styles from)

              3. Global clash resolution strategy (load all with overwrite, load all with rename or do not load the style)

               

              See this method documented e.g. here for inDesign CS6:

              Adobe InDesign CS6 (8.0) Object Model JS: Document

               

              Regards,
              Uwe

              1 person found this helpful
              • 4. Re: Evoke: Load Table Cells and Styles...
                Laubender Adobe Community Professional & MVP

                Or you are writing a custom function where you open a document where you know that the appropriate styles are present, add a new table using the styles you need and move that table to your document where you need the styles.

                 

                Regards,
                Uwe

                • 5. Re: Evoke: Load Table Cells and Styles...
                  [Jongware] Most Valuable Participant

                  Count your open and close braces: the final try..catch part is not part of the function above it, nor from the 'main' program.

                   

                  Try placing these lines above the 'exit()' command and see if they do anything. (Uwe's way is better but those new lines of code should still be reachable.)

                  • 6. Re: Evoke: Load Table Cells and Styles...
                    Pete Stan Level 1

                    Placed it as you said and it does seem to work ok! (just need more testing)

                     

                    //Jongware's PrepText starts here
                    if (app.activeDocument.selection[0].constructor.name != "InsertionPoint")
                    {
                        alert ("Cursor in "+app.activeDocument.selection[0].constructor.name+"\nPlease put the cursor into a text frame");
                        exit(0);
                    }
                    
                    var myMaximumValue = 63;
                    var myProgressBarWidth = 384;
                    var myIncrement = myMaximumValue/myProgressBarWidth;
                    myCreateProgressPanel(myMaximumValue, myProgressBarWidth);
                    
                    myProgressPanel.myProgressBar.value = 0;
                    myCreateProgressPanel(100, 400);
                    myProgressPanel.show();
                    
                    for (b=0; b<2; b++)
                    {
                        for (i=0; i<2; i++)
                        {
                            for (s=0; s<2; s++)
                            {
                                for (u=0; u<2; u++)
                                {
                                //    Don't process strikeout
                                    for (k=0; k<1; k++)
                                    {
                                        for (c=0; c<2; c++)
                                        {
                                            if (b+i+s+u+k+c)
                                            {
                                                myProgressPanel.myProgressBar.value = 32*b+16*i+8*s+4*u+2*k+c;
                                                findAttr (b, i, s, false, u, /*k*/false, c, "");
                                                if (s)
                                                    findAttr (b, i, false, s, u, /*k*/false, c, "");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    myProgressPanel.hide();
                    
                    //Load Table and Cell styles
                    var loadStyles = app.menuActions.itemByID(132109).invoke();
                       
                    exit(0);
                    
                    function myCreateProgressPanel(myMaximumValue, myProgressBarWidth)
                    {
                        myProgressPanel = new Window('window', 'Prepping text');
                        with(myProgressPanel)
                        {
                            myProgressPanel.myProgressBar = add('progressbar', [12, 12, myProgressBarWidth, 24], 0, myMaximumValue);
                        }
                    }
                    
                    function findAttr (bold, italic, superscript, subscript, underline, strikeout, smallcaps, StyleName)
                    {
                        app.findTextPreferences = NothingEnum.nothing;
                        app.changeTextPreferences = NothingEnum.nothing;
                        app.findTextPreferences.appliedCharacterStyle = app.activeDocument.characterStyles[0];    // "[None]"
                    
                        app.findTextPreferences.fontStyle = "Regular";
                        app.findTextPreferences.position = Position.normal;
                        app.findTextPreferences.capitalization = Capitalization.normal;
                        app.findTextPreferences.underline = false;
                        app.findTextPreferences.strikeThru = false;
                    
                        if (bold)
                        {
                            if (italic)
                                app.findTextPreferences.fontStyle = "Bold Italic";
                            else
                                app.findTextPreferences.fontStyle = "Bold";
                        } else
                        {
                            if (italic)
                                app.findTextPreferences.fontStyle = "Italic";
                        }
                        if (superscript)
                            app.findTextPreferences.position = Position.superscript;
                    
                        if (subscript)
                            app.findTextPreferences.position = Position.subscript;
                    
                        if (underline)
                            app.findTextPreferences.underline = true;
                        if (strikeout)
                            app.findTextPreferences.strikeThru = true;
                        if (smallcaps)
                            app.findTextPreferences.capitalization = Capitalization.smallCaps;
                    
                        foundItems = app.activeDocument.selection[0].parent.findText();
                    
                        if (foundItems.length > 0)
                        {
                            if (StyleName == "")
                            {
                            //    Make up a name
                                if (bold)
                                    StyleName = "Bold";
                                if (italic)
                                {
                                    if (bold)
                                        StyleName = "Bold Italic";
                                    else
                                        StyleName = "Italic";
                                }
                                if (superscript)
                                {
                                    if (StyleName) StyleName += " + ";
                                    StyleName += "Super";
                                }
                                if (subscript)
                                {
                                    if (StyleName) StyleName += " + ";
                                    StyleName += "Sub";
                                }
                                if (underline)
                                {
                                    if (StyleName) StyleName += " + ";
                                    StyleName += "Underline";
                                }
                                if (strikeout)
                                {
                                    if (StyleName) StyleName += " + ";
                                    StyleName += "Stkout";
                                }
                                if (smallcaps)
                                {
                                    if (StyleName) StyleName += " + ";
                                    StyleName += "Scaps";
                                }
                                try
                                {
                                    cstyle = app.activeDocument.characterStyles.add({name:StyleName}); // , fontStyle:app.findTextPreferences.fontStyle, underline:app.findTextPreferences.underline, strikeThru:app.findTextPreferences.strikeThru, position:app.findTextPreferences.position, capitalization:app.findTextPreferences.capitalization});
                                    if (bold || italic) cstyle.fontStyle = app.findTextPreferences.fontStyle;
                                    if (superscript || subscript) cstyle.position = app.findTextPreferences.position;
                                    if (underline) cstyle.underline = app.findTextPreferences.underline;
                                    if (strikeout) cstyle.strikeThru = app.findTextPreferences.strikeThru;
                                    if (smallcaps) cstyle.capitalization = app.findTextPreferences.capitalization;
                                } catch (e)
                                {
                                }
                            }
                            app.changeTextPreferences.appliedCharacterStyle = StyleName;
                            app.activeDocument.selection[0].parent.changeText (false);
                        }
                    }
                    

                     

                    What would be the way to apply the Body Text Paragraph Style to all the text that is already [No Paragraph Style]? The tricky part is: I always have a Body Text Paragraph Style that comes in group named EN, HB or AR (but it's always named Body Text)?