Skip navigation
Currently Being Moderated

Character/Paragraph Style Hilight colors

Feb 4, 2012 8:56 PM

Tags: #background #javascript #preview #overrides

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

 
Replies
  • Currently Being Moderated
    Feb 4, 2012 9:55 PM   in reply to [Jongware]

    Nice find Theun!

     

    Thanks for sharing!

     

    Harbs

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Feb 4, 2012 10:28 PM   in reply to [Jongware]

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

    Nice!

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 6, 2012 7:26 AM   in reply to John Hawkinson

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

     

    Best Regards

    Roland

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 6, 2012 8:10 AM   in reply to [Jongware]

    This is awesome! Thanks for sharing.

     

    Is someone working on the palette to manage it?

     

    Jeff

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 6, 2012 9:19 AM   in reply to absqua

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2012 12:22 AM   in reply to absqua

    @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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2012 1:59 AM   in reply to Laubender

    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)

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2012 4:12 AM   in reply to Marijan Tompa

    @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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2012 5:05 AM   in reply to Laubender

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2012 6:05 AM   in reply to [Jongware]

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

     

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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2012 7:34 AM   in reply to [Jongware]

    @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

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Feb 7, 2012 10:18 AM   in reply to [Jongware]

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2012 11:30 AM   in reply to [Jongware]

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2012 11:58 AM   in reply to [Jongware]

    @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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2012 2:43 PM   in reply to [Jongware]

    That's utterly cool! Thanks for sharing!

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2012 1:20 AM   in reply to [Jongware]

    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-st yles — 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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2012 2:16 AM   in reply to [Jongware]

    > [...] 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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2012 10:26 AM   in reply to [Jongware]

    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.

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Jun 4, 2012 6:50 PM   in reply to Dirk Becker

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (2)