Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding Highlight to script Or Grep Style?

Advisor ,
Jul 20, 2016 Jul 20, 2016

Hi

Is it possible to Add a hightlight to a script?  Basically what i want it to do is Highlight text and the tricky part is that the text changes sizes depending on the size of file we're working on.  Say i want to automatically highlight this "FOR PROFESSIONAL USE ONLY" the way we do it now is Make a underline the like this in the underline options menu: Say my font size is 8, Leading 9.6 (These will always change).

Weight:  =   9.6

Offset:  =   -8*.33

Color = Yellow

That is the way we do it now.  Can it be scripted or Grep style even that will automatically do this for certain Lines of text only?  And no matter the size of font calculate what it needs to so whether its 2pt, 10pt 100pt etc... it will Highlight the specified text correctly?

hopefully this is possible.. 

Thank you

TOPICS
Scripting
7.4K
Translate
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 1 Correct answer

Mentor , Jul 25, 2016 Jul 25, 2016

The below one is a better.

I removes a bug and also if no "what" is provided to the highlight function and there's no entry in the find what of the find text panel and some text is selected then that text will be highlighted.

An idea in the script is that a keyboard short cut can be applied for it and it will get it's info from the find text panel.

So for the meantime change the correct answer to this one

// Highlight function by Trevor

// http://creative-scripts.com

// Custom Scripts for Adobe InDes

...
Translate
Mentor ,
Jul 20, 2016 Jul 20, 2016

Hi Chris

What about applying a conditional text? That would be easy. Then you could just do a manual or scripted find change text to apply the condition.

Set the condition to print if desired.

This solution is going to depend on your workflow.

Screen Shot 2016-07-21 at 00.12.46.png

HTH

Trevor

Translate
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
Advisor ,
Jul 21, 2016 Jul 21, 2016

I never even knew about Conditional Text.  I'm going to try that today.  Thanks for the Great tip

Translate
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
Advisor ,
Jul 21, 2016 Jul 21, 2016

This actually works just like i'm wanting.  I'm just going to need to try and put it in a script.  Can this be handled with GREP somehow?

Translate
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
Mentor ,
Jul 21, 2016 Jul 21, 2016

Hi

You don't need to grep just use.

var doc = app.activeDocument;

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.findWhat = 'FOR PROFESSIONAL USE ONLY';

// note the necessary [] around the condition(s)

app.changeTextPreferences.appliedConditions = [doc.conditions.itemByName('Highlight')]; // Change to correct name

doc.changeText();

Translate
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
Advisor ,
Jul 21, 2016 Jul 21, 2016

This is perfect.  Thank you so so so much. 

Translate
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
Advisor ,
Jul 22, 2016 Jul 22, 2016

I'm actually running into a problem here.  It highlights a yellow Greenish color.  WHen i do separations preview it comes out As just yellow but when i export to PDF it comes out 84% yellow and 4% cyan.  Making of course a green color.  Any idea how to keep it Pure Yellow?

Translate
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
Mentor ,
Jul 22, 2016 Jul 22, 2016

That's one o the things I meant when I wrote "depends on your workflow"

The problem is that the conditional colors are rgb and not cmyk.

You need to set the conditions indicatorColor properties as best as you can.

Translate
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
Advisor ,
Jul 22, 2016 Jul 22, 2016

is there anyway to convert them to CMYK that you know of? the code i'm using to indicate the color is

colorToHighlig = doc.conditions.add ({name:"Highlight",indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor:UIColors.YELLOW});

When i tried Y=100 it of course does not work.

Translate
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
Mentor ,
Jul 22, 2016 Jul 22, 2016

Create a cmyk swatch then convert it to rgb to get the rgn values

I think the need to be in an array of 3 values up to 255

Another way to do it is do a scripted find text and apply a yellow strikethrough line to the finds of the leading thickness in points of the characters

I can't post any code for that now but it's dead easy stuff and that way you won't get any cmyk problems

You could try the same idea with underline

Best of luck

Translate
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
Advisor ,
Jul 22, 2016 Jul 22, 2016

I've added a custom Yellow C=0 M=0 Y=100 K=0 to my Colors In the Conditional Text that is in CMYK.  Thought i was onto something but it showed up as more green .  Darn.  I'll try the scripting here soon.  Because this Would Be great if the Conditional Text would just work the way i want it to..  

Translate
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
LEGEND ,
Jul 22, 2016 Jul 22, 2016

Chris,

Imho, it's a simple question for PitStop! 

Here, 2 samples of a "Yellow" condition converted to Cyan 50%!

Capture d’écran 2016-07-23 à 01.14.11.png

As you can see, the "Yellow" color is:  C6  M0  Y87  N0

In fact, not true, the real values are given by the PitStop Inspector:  C5.8  M0  Y86.8  N0

Using PitStop, I just decide to convert the color:  C5.8  M0  Y86.8  N0  to the color:  C50  M0  Y0  N0  [for sample]

1 click!    [ I could save the action and play it for other pdf exported from ID using this "Yellow" condition! ]

Capture d’écran 2016-07-23 à 01.15.07.png

Translate
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
Advisor ,
Jul 25, 2016 Jul 25, 2016

The down side to this is that we would have to do this with all our PDF's which in our case is thousands a month.

Translate
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
Mentor ,
Jul 25, 2016 Jul 25, 2016

Working on something now, will post it in a few minutes.

Translate
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
Mentor ,
Jul 25, 2016 Jul 25, 2016

Hi Chris

Please mark this one as the 'Correct answer'

Read the annotations

I shall try do something with using strike through instead of underline so that one can have the text underlined also

// Highlight function by Trevor

// http://creative-scripts.com

// Custom Scripts for Adobe InDesign, Illustrator and a lot more

// Draft Version 1

// https://forums.adobe.com/message/8898663#8898663

function highlight(what, color) {

    var range, s, doc;

    doc = app.properties.activeDocument;

    if (!doc) {

        return 'No Active Document';

    }

    s = app.selection && app.selection[0];

    range = (s && s.properties.underline !== undefined && s.characters.length) ? s : doc;

    app.doScript(f, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Highlight Text');

    function f() {

        var doc, finds, find, l, leading, pointSize, currentChangeProps;

        color = color || app.colors.itemByName('Yellow');

        // Store current find change text settings

        currentFindTextWhat = app.findTextPreferences.findWhat;

        currentChangeProps = app.changeTextPreferences.properties;

        // if no what is provided then the current entry in the find text panel will be used

        if (what) { app.findTextPreferences.findWhat = what; }

        app.changeTextPreferences.changeTo = '';

        app.changeTextPreferences.underline = true;

        app.changeTextPreferences.underlineColor = color;

        finds = range.findText();

        range.changeText();

        l = finds.length;

        while (l--) {

            find = finds;

            leading = find.leading;

            pointSize = find.pointSize;

            leading = pointSize * find.autoLeading / 100;

            find.underlineWeight = leading + 'pt'; // This is presuming that font and leading size is set to points!

            find.underlineOffset = (pointSize - leading) * 1.5; // The 1.5 might need tweaking but seems to work well

        }

        app.findTextPreferences.findWhat = currentFindTextWhat;

        app.changeTextPreferences.properties = currentChangeProps;

    }

}

/************************************************************************************************************************************

** If text is selected then the "highlighting" is only applied within the selected text                                            **

** Otherwise the "highlighting" is applied within the whole document                                                               **

** One could change this to apply to what ever is selected in the Find text document if one wanted to                              **

** To highlight the word(s) in the find text panel just use highlight(); or highlight(undefined, app.activeDocument.swatches[5]);  **

** One can use highlight('Foo'); to highlight "foo" and ignore what's in the find text panel                                       **

** The formating / styles etc. for the find are taken from the find panel                                                          **

** If one provides a swatch as the second argument highlight(undefined, app.activeDocument.swatches[5]); that swatch will be used  **

** otherwise yellow will be used                                                                                                   **

************************************************************************************************************************************/

highlight();

Translate
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
Mentor ,
Jul 25, 2016 Jul 25, 2016

Doesn't look like the strike though option is good but the above solution looks like it works well.

Edit:

Just to explain the colors

Yellow is the highlighted color

Blue is a conditional text highlight

Black is selected text

The half blue fred was added after the script was run.

Screen Shot 2016-07-25 at 15.58.58.png

Translate
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
Mentor ,
Jul 25, 2016 Jul 25, 2016

The below one is a better.

I removes a bug and also if no "what" is provided to the highlight function and there's no entry in the find what of the find text panel and some text is selected then that text will be highlighted.

An idea in the script is that a keyboard short cut can be applied for it and it will get it's info from the find text panel.

So for the meantime change the correct answer to this one

// Highlight function by Trevor

// http://creative-scripts.com

// Custom Scripts for Adobe InDesign, Illustrator and a lot more

// Beta Version 1

// https://forums.adobe.com/message/8898663#8898663

function highlight(what, color) {

    var range, s, doc;

    doc = app.properties.activeDocument;

    if (!doc) {

        return 'No Active Document';

    }

    s = app.selection && app.selection[0];

    range = (s && s.properties.underline !== undefined && s.characters.length) ? s : doc;

    app.doScript(f, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Highlight Text');

    function f() {

        var finds, find, l, leading, pointSize, currentChangeProps;

        color = color || app.activeDocument.colors.itemByName('Yellow');

        // Store current find change text settings

        currentFindTextWhat = app.findTextPreferences.findWhat;

        currentChangeProps = app.changeTextPreferences.properties;

        what = what || currentFindTextWhat;

        if (what !== '') {

            // if no what is provided then the current entry in the find text panel will be used

            app.findTextPreferences.findWhat = what;

            app.changeTextPreferences.changeTo = '';

            app.changeTextPreferences.underline = true;

            app.changeTextPreferences.underlineColor = color;

            finds = range.findText();

            range.changeText();

            l = finds.length;

            while (l--) {

                find = finds;

                leading = find.leading;

                pointSize = find.pointSize;

                leading = pointSize * find.autoLeading / 100;

                find.underlineWeight = leading + 'pt'; // This is presuming that font and leading size is set to points!

                find.underlineOffset = (pointSize - leading) * 1.5; // The 1.5 might need tweaking but seems to work well

            }

            app.findTextPreferences.findWhat = currentFindTextWhat;

            app.changeTextPreferences.properties = currentChangeProps;

        } else if (range !== app.activeDocument) {

            leading = range.leading;

            pointSize = range.pointSize;

            leading = pointSize * range.autoLeading / 100;

            range.underline = true;

            range.underlineColor = color;

            range.underlineWeight = leading + 'pt'; // This is presuming that font and leading size is set to points!

            range.underlineOffset = (pointSize - leading) * 1.5; // The 1.5 might need tweaking but seems to work well

        }

    }

}

/***************************************************************************************************************************************

** If text is selected then the "highlighting" is only applied within the selected text                                              **

** Otherwise the "highlighting" is applied within the whole document                                                                **

** One could change this to apply to what ever is selected in the Find text document if one wanted to                                **

** To highlight the word(s) in the find text panel just use highlight(); or highlight(undefined, app.activeDocument.swatches[5]);    **

** One can use highlight('Foo'); to highlight "foo" and ignore what's in the find text panel                                        **

** The formating / styles etc. for the find are taken from the find panel                                                            **

** If one provides a swatch as the second argument highlight(undefined, app.activeDocument.swatches[5]); that swatch will be used    **

** otherwise yellow will be used                                                                                                    **

** If one provides a swatch as the second argument highlight(undefined, app.activeDocument.swatches[5]); that swatch will be used    **

** If text is selected and what argument is given and the find what in the find panel is empty then the selected text is highlighted **

**************************************************************************************************************************************/

highlight();

Translate
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
LEGEND ,
Jul 25, 2016 Jul 25, 2016

Hi Trevor,

Very smart and very cool! 

Would it not be more interesting to play it with find/change-Grep and grep styles to keep the para styles pure?

It could be problematic if text already underlined!

Translate
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
Advisor ,
Jul 25, 2016 Jul 25, 2016

My Friend this is awesome.  Thank you so much.  I'm just going to play around and see if i can get this to automatically highlight my text (For Professional Use)(For Professional use Not to be sold seperatlely.) etc.  In my case as stated in the code i had to adjust the 1.5 a little but not too much.  Below is what i'm trying to get it to Automatically Highlight My text.

currentFindTextWhat = app.findTextPreferences.findWhat = 'FOR PROFESSIONAL USE ONLY-NOT INTENDED FOR HOUSEHOLD USE.', 'POUR USAGE PROFESSIONNEL SEULEMENT - NON DESTINÉ À L’USAGE DOMESTIQUE.';

will i need to have several different app.findTextPreferences.findWhat= statements?

Translate
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
Advisor ,
Jul 25, 2016 Jul 25, 2016

I've also tried this.  It only does the First findWhat.  So i think i might be on the right track since it kinda works?

var finds, find, l, leading, pointSize, currentChangeProps, currentChangeProps1, currentChangeProps2; 

            color = color || app.activeDocument.colors.itemByName('Yellow'); 

            // Store current find change text settings

            currentFindTextWhat = app.findTextPreferences.findWhat;

            app.findTextPreferences.findWhat = 'POUR USAGE PROFESSIONNEL SEULEMENT - NON DESTINÉ À L’USAGE DOMESTIQUE.';

            currentChangeProps = app.changeTextPreferences.properties;

            app.findTextPreferences.findWhat = 'PARA USO PROFESIONAL SOLAMENTE: NO ESTÁ DISEÑADO PARA USO DOMÉSTICO.';

            currentChangeProps1 = app.changeTextPreferences.properties;

            app.findTextPreferences.findWhat = 'FOR PROFESSIONAL USE ONLY-NOT INTENDED FOR HOUSEHOLD USE.'; 

            currentChangeProps2 = app.changeTextPreferences.properties;

             what = what || currentFindTextWhat;

Translate
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
Mentor ,
Jul 25, 2016 Jul 25, 2016

I'm confused, just include the function in your script and then do

highlight('fred');

highlight('Trevor');

highlight('Chris');

That will highlight whatever your want.

Did you read the annotations?

Translate
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
Advisor ,
Jul 26, 2016 Jul 26, 2016

Sorry i miss read it.  I see it now.  Thank you. 

Translate
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
Participant ,
Oct 11, 2018 Oct 11, 2018

Hi,

Its working fine to find the single word. Please guide me how to add more words/greps in this scripts.

Thanks in advance.

by

hasvi

Translate
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
Mentor ,
Oct 11, 2018 Oct 11, 2018

See #20 above.

Remove line 71 and add your list of words.

highlight('fred');

highlight('Trevor');

highlight('Chris');

highlight('hasvi');

highlight('\\d+');

highlight('some phase here');

highlight('the', app.activeDocument.swatches[4]); \\ second optional field is the swatch defaults to yellow

Translate
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
Participant ,
Oct 11, 2018 Oct 11, 2018

Hi,

Thanks for your guideline, but I am getting error for below lines, please advice.

highlight('(\d+)-(\d+)'); //find the hyphen between the numbers

highlight('the' 'word', app.activeDocument.swatches[4]); // second optional field is the swatch defaults to yellow

Thanks again.

by

hasvi

Translate
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