22 Replies Latest reply: Jun 4, 2012 6:50 PM by John Hawkinson RSS

    Character/Paragraph Style Hilight colors

    [Jongware] MVP

      In May 2010 Marc Autret posted this interesting blog: Show Local Formatting in InDesign CS4/CS5, where he shows how an undocumented feature of InDesign can be put to good use. If you set TextPreference.enableStylePreviewMode to true, ID suddenly shows red lines marking local character and paragraph style overrides.  A very neat find, one that I use all the time to check my documents for (uh) "neatness".

       

      I just ran across this obscure scripting preference whilst looking for something entirely unrelated -- but something in the description caught my eye.

       

      enableStylePreviewModeboolr/wIf true, highlights character and paragraph styles with colored backgrounds.

       

      Regular lurkers might remember the puzzling "previewColor" properties in Paragraph and Character Style. Now that's what this is for!

       

      This script will add background colors to a paragraph style and a character style, and then show them in your document. No need to worry about your document, despite the name they only appear in Normal view. In Preview mode they disappear, and they will not print or export to PDF.

       

      app.activeDocument.textPreferences.enableStylePreviewMode = true;
      app.activeDocument.paragraphStyles.item("Body Text").previewColor = UIColors.YELLOW;
      app.activeDocument.characterStyles.item("Italics").previewColor = UIColors.CYAN;
      

       

      Upside or downside is this comes with those override red line markings for free. Oh well. Perhaps it's a preference in CS6 -- and I wouldn't mind if the preview color could be set in the style options either, for now it needs a script.

       

      Screen Shot 2012-02-05 at 5.35.21 AM.png

        • 1. Re: Character/Paragraph Style Hilight colors
          Harbs. MVP

          Nice find Theun!

           

          Thanks for sharing!

           

          Harbs

          • 2. Re: Character/Paragraph Style Hilight colors
            John Hawkinson Community Member

            Dang! You know, I was this close earlier this week, when somebody asked about previewColor...if only I'd completed the thought!

            Nice!

            • 3. Re: Character/Paragraph Style Hilight colors
              drerol74 Community Member

              Yes, I've asked for it and here is the answer.  Thanks Jongware!

               

              Best Regards

              Roland

              • 4. Re: Character/Paragraph Style Hilight colors
                absqua Community Member

                This is awesome! Thanks for sharing.

                 

                Is someone working on the palette to manage it?

                 

                Jeff

                • 5. Re: Character/Paragraph Style Hilight colors
                  absqua Community Member

                  I'm definitely seeing some weirdness, though (in CS5 7.0.4 on Mac 10.6.8). If I do this:

                   

                  app.selection[0].appliedParagraphStyle.previewColor = UIColors.YELLOW
                  

                   

                  I see this:

                   

                  Screen shot 2012-02-06 at 11.12.44 AM.PNG

                   

                  Not yellow. If I assign an RGB value, like [255, 0, 0], it takes, but doesn't display any highlight color. I checked how other things, like xmlTags, that use the UIColors, look, and the colors do display properly there.

                   

                  Does anyone else see this?

                  • 6. Re: Character/Paragraph Style Hilight colors
                    Laubender MVP

                    @Jongware – Cool. Thanks for sharing.
                    Same observation, though different color: an asigned RGB value like [255,255,0] (=bright yellow) turns to nothing, UIColors like YELLOW or CYAN turn into different colors:

                     

                    var _d = app.activeDocument;
                    var _allParaStyles = _d.allParagraphStyles;
                    
                    var _UIColor = UIColors.YELLOW;
                    
                    _d.guidePreferences.rulerGuidesColor = _UIColor;
                    _d.textPreferences.enableStylePreviewMode = true;
                    _allParaStyles[1].previewColor = _UIColor;
                    
                    app.selection[0].contents = "UIColors."+_UIColor.toString();
                    

                     

                    Look at the vertical guide. Its color is "UIColors.YELLOW":

                    PreviewColor_UIColors.YELLOW.png

                    Here a version with "UIColors.CYAN":

                    PreviewColor_UIColors.CYAN.png

                     

                    (InDesign CS5.5 v7.5.2 German with OSX 10.6.8)

                     

                     

                    Uwe

                    • 7. Re: Character/Paragraph Style Hilight colors
                      Marijan Tompa [tomaxxi] UGM-MVPs

                      Nice find!

                      I'm also seeing color offset, also, colors from GRID_BLUE and beyond, doesn't work.

                       

                      var
                          mD = app.activeDocument,
                          pS = mD.paragraphStyles, pSn,
                          tB = mD.textFrames.add ( { geometricBounds: [0, 0, "200mm", "200mm"] } );
                      
                      mD.textPreferences.enableStylePreviewMode = true;
                          
                      for each ( color in UIColors ) {
                          try { pSn = pS.add ( { name: color.toString () } ); } catch ( _ ) { pSn = pS.itemByName ( color.toString () ) };
                          pSn.previewColor = color ;
                          tB.insertionPoints [-1].contents = "Test " + color.toString () + "\r";
                          tB.paragraphs [-1].appliedParagraphStyle = pS.itemByName ( color.toString () );
                      }
                      

                       

                      --

                      Marijan (tomaxxi)

                      • 8. Re: Character/Paragraph Style Hilight colors
                        Laubender MVP

                        @Marijan – just made a list of all UIColors. See the screenshot. The yellow rectangle is a indicator if a specific color turned to nothing or to white (InDesign CS5.5 v7.5.2 on Mac OS X 10.6.8).

                         

                        "GRID_BLUE" in this case turned to white, "LIGHT_BLUE" turned to black…

                         

                        PreviewColor_ALL_UIColors.png

                         

                         

                        Uwe

                        • 9. Re: Character/Paragraph Style Hilight colors
                          Laubender MVP

                          Ok. Now I tested with InDesign CS4 and CS5. In CS4 the right UIColors were applied, CS5 and CS5.5  wrong colors. Seems to be a bug that sneeked in when CS5 came out.

                           

                          Uwe

                          • 10. Re: Character/Paragraph Style Hilight colors
                            [Jongware] MVP

                            Oh drat. Yeah I do my daily work with '4 and it *seemed* to work fine :)

                             

                            So not even supplying custom colors work? Is it possible to file a bug report on an unsupported function? :D

                            • 11. Re: Character/Paragraph Style Hilight colors
                              Harbs. MVP

                              I'd guess the problem was introduced by the new enums introduced in CS5.

                               

                              But, setting them using the values doesn't help...

                              • 12. Re: Character/Paragraph Style Hilight colors
                                Laubender MVP

                                @Jongware – applying a custom color is crashing InDesign CS4 in the moment you switch from "Preview" (w) to "Layout" view; or immediately, if you are already in "Layout" view. That is not new to me. Applying a custom color to a page in the pages panel would crash (BEGIN EDIT) InDesign CS5 and CS5.5 (END EDIT) as well, if the palette is visible in the UI.

                                 

                                (BEGIN EDIT:
                                Example for CS5 and CS5.5:

                                 

                                app.documents[0].pages[0].pageColor = [255,255,0];
                                

                                 

                                will crash InDesign in the moment the pages panel is visible. If it is hidden behind other UI elements or not visible at all, InDesign will not crash.
                                (END EDIT)

                                 

                                In CS5 or CS5.5 applying a custom color to a paragraph style with previewColor results in nothing.

                                 

                                Uwe

                                 

                                Message was edited by: Laubender

                                • 13. Re: Character/Paragraph Style Hilight colors
                                  John Hawkinson Community Member

                                  Jongware:

                                  Is it possible to file a bug report on an unsupported function?

                                  Sure. By one analysis, it is more likely to get fixed, because there is no one depending on the old, documented behavior!

                                  • 14. Re: Character/Paragraph Style Hilight colors
                                    [Jongware] MVP

                                    I apologize, guys & gals, for getting your hopes up. It all works fine & dandy in CS4, preview or no preview

                                     

                                    Screen Shot 2012-02-07 at 7.47.35 PM.png

                                     

                                    Reported as a Bug for CS5 and newer.

                                    • 15. Re: Character/Paragraph Style Hilight colors
                                      absqua Community Member

                                      There is an order to how the UIColors are off, though—they're all off by two. This works (although LIGHT_BLUE and RED are gone); I ran it on a document with an empty text frame.

                                       

                                      function main() {
                                          var doc = app.activeDocument,
                                              colors = [],
                                              map = {},
                                              story = doc.stories[0],
                                              i, style;
                                      
                                          for (i in UIColors) {
                                              colors[colors.length] = UIColors[i];
                                          }
                                      
                                          for (i = 2; i < colors.length; i++) {
                                              map[colors[i].toString()] = colors[i - 2];
                                          }
                                              
                                          for (i in map) {
                                              style = doc.paragraphStyles.add({name: i});
                                              style.previewColor = map[i];
                                              story.insertionPoints[-1].contents = "UIColors." + i + "\r";
                                              story.paragraphs[-1].appliedParagraphStyle = style;
                                          }
                                      
                                          doc.textPreferences.enableStylePreviewMode = true;
                                      }
                                      
                                      app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Show Preview Colors");
                                      

                                       

                                      Then I guess the person who isn't me who is making the dialog to manage this could at least use e.g. UIColors.GREEN for CS4 and map.GREEN for CS5.

                                      • 16. Re: Character/Paragraph Style Hilight colors
                                        Laubender MVP

                                        @Jongware – and the following script will crash InDesign CS4 (not CS5 and CS5.5) if in "Layout" view, but not in "Preview" (text frame selected):

                                         

                                        //CAUSION: Will crash InDesign CS4 immediately if in "layout" view.
                                        //Will crash InDesign CS4 after applying previewColor if changing from "preview" view to "layout" view!
                                        
                                        
                                        var d = app.documents[0];
                                        var sel = app.selection[0]; //TextFrame
                                        
                                        d.textPreferences.enableStylePreviewMode = true;
                                        
                                        var RGBcolor = [255,255,0]; //Bright yellow color
                                        
                                        sel.insertionPoints[0].contents = "RGBcolor "+"["+RGBcolor.toString()+"]";
                                        sel.insertionPoints[0].appliedParagraphStyle = d.allParagraphStyles[1];
                                        
                                        d.allParagraphStyles[1].previewColor = RGBcolor;
                                        

                                         

                                        Uwe

                                        • 17. Re: Character/Paragraph Style Hilight colors
                                          RorohikoKris Community Member

                                          That's utterly cool! Thanks for sharing!

                                          • 18. Re: Character/Paragraph Style Hilight colors
                                            Marc Autret Community Member

                                            Hi Jongware,

                                             

                                            Shame on me! I just discovered this thread today (June 4!) thanks to a link found at http://indesignsecrets.com/style-highlighting.php

                                             

                                            It follows that when I posted in May the very first version of StyLighter  — http://www.indiscripts.com/post/2012/05/the-hidden-way-to-highlight-styles — I had not the slightest knowledge of everything that was discussed here!

                                             

                                            So I really want to apologize for having covered up (although unintentionally) your own discovery.

                                             

                                            @+

                                            Marc

                                            • 19. Re: Character/Paragraph Style Hilight colors
                                              [Jongware] MVP

                                              Apologies not necessary. That previewColor property has been a mystery for quite some time, and when I finally found out what it is supposed to do, it seemed to be so bug-ridden that I quickly steered away from it and I gave up attempting to make any sense of it. But your script just avoids those bugs popping up!

                                               

                                              As I said in the IDS post: it's rather sad the Adobe team gave up on further developing this great hidden feature into a full one; and it's downright worrying that they left that legacy code in CS5 and later, so it could get infested with all those nasty little bugs. It leads me to think: how many more 'dead' code is there, in CS5, 5.5 and now in CS6? Could that be the reason later versions are so much slower and more buggy than my trusty CS4?

                                               

                                              (Point in fact.

                                               

                                              In CS4 and earlier on the Mac, all plugin resources are gathered into neat, small packages inside a single large indexed file. That makes sense, because every single plugin resource is just a couple of bytes long -- say, a single icon, or a single string "Menu Item Name". With CS5, the programmers suddenly took a Lazy Turn and wrote out every single resource as a single small file. That means that

                                               

                                              1. (Annoying!) Since hard disk space is allocated by the kilobyte (typically 4Kb chunks), 10 tiny resources totalling 1 Kb now will suddenly occupy 40 Kb of disk space. Sure, hard disk space is cheap. Apparently, it's even cheaper than doing some programming -- or even just using the load code from the last version!

                                               

                                              2. (Frustrating!) Locating, opening, loading, and then closing a single file takes time and resources, but after a file got loaded into memory, you can do with it whatever you want. Locating, opening, loading and then closing each of the dozens of small files per plugin takes lots of time. Is that the reason CS5.5 starts up so incredibly slow? Jongware sez: yeah for sure it won't help.

                                               

                                              /Point in fact).

                                              • 20. Re: Character/Paragraph Style Hilight colors
                                                Marc Autret Community Member

                                                > [...] Could that be the reason later versions are so much slower and more buggy than my trusty CS4?

                                                 

                                                Yep, I think so.

                                                ID CS4 remains my yardstick so far.

                                                 

                                                @+

                                                Marc

                                                • 21. Re: Character/Paragraph Style Hilight colors
                                                  Dirk Becker Community Member

                                                  Jongware,

                                                   

                                                  the conversion to those files was probably undertaken to get away from OSX Carbon resource manager which is not thread safe and not available as 64bit version. Why Adobe did not implement anything less wasteful is beyond me, but they are again in good company with Apple, who uses packages / folder hierarchies galore where frugal old school developers stuffed everything into a single resource fork.

                                                   

                                                  On the other hand CS5.5 takes about two seconds to launch on my current Mac (with SSD) while CS4 took about 30 seconds on an old disk based machine.

                                                  • 22. Re: Character/Paragraph Style Hilight colors
                                                    John Hawkinson Community Member

                                                    Just wait. For CS7 they will hear your request and bundle them as monolithic zip files.