Skip to main content
Inspiring
October 5, 2015
Answered

Delete conditional text

  • October 5, 2015
  • 3 replies
  • 2190 views

In my selected text having two conditional texts (red and green). I needs to remvoe the red conditional text from the selected text

How to do this

This topic has been closed for replies.
Correct answer rob day

Hi @Chase29247725h4qr , In case Marc does not see your question /*Text*/ is an efficient way of commenting on the parameters—tells you the tx parameter needs to be a Text object. You could also write comments above the function, depends on your coding preferences, might be something like this where the comments are in green. Code between /* and */ gets commented out:

 

 

3 replies

Adobe Expert
November 23, 2021

blockstation said:

"I've got several documents open and I'd like to delete in all documents the applied condition, while the text of the condition is preserved."

 

Hi blockstation,

you want to do something entirely else than our OP here wanted. You want to remove conditions, he wanted to remove text where a specific condition was applied to.

So you need different code. It has nothing to do with a GREP Find/Replace action.

Conditions are properties of the document. And can be removed if you know the names.

 

Examples:

So you should be able to remove a condition named "foo" from the document like that:

app.documents[0].conditions.itemByName("foo").remove();

If you want to do that for all open documents:

app.documents.everyItem().conditions.itemByName("foo").remove();

 

If you want to remove all conditions from all open documents:

app.documents.everyItem().conditions.everyItem().remove();

 

Regards,
Uwe Laubender

( ACP )

blockstation
Known Participant
November 24, 2021

Thank you very much, this was very helpful.

 

blockstation
Known Participant
November 24, 2021

Just for reference, is it also possible to add a condition to all open documents?

Adobe Expert
October 5, 2015

Or maybe just this:

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.appliedConditions = ['red'];

app.selection[0].changeGrep();

Peter

blockstation
Known Participant
November 23, 2021

Soory for opening up this old thread, but it doesn't work out for me.

When I try

 

app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.appliedConditions = ['red'];
app.selection[0].changeGrep();

 

I only receive "undefined is not an object" - I'm working with the 2021 release of InDesign.

I use the ExtendScript Toolkit, InDesign is selected as target and the file is saved as .jsx.

Do I miss something?

 

blockstation
Known Participant
November 23, 2021

The script expects some selected text or a text frame. To target a document without selecting anything, change app.selection[0] to app.documents[0].


Thank you for the fast answer Peter.

Unfortunatly this neither worked out for me.

Maybe I'm doing something wrong.

So here is my scenario:

I've got several documents open and I'd like to delete in all documents the applied condition, while the text of the condition is preserved.

I only use the mentioned script, nothing more.

 

Marc Autret
Brainiac
October 5, 2015

Try this:

(function removeConditionalText(/*Text*/tx,/*UIColor*/uiColor,/*bool=false*/STRICT)

// -------------------------------------

// Remove any text within tx having a uiColor condition applied.

// (If STRICT is true, do not affect text undergoing multiple conditions.)

{

    var ranges = tx.textStyleRanges,

        a = ranges.everyItem().getElements(),

        conds = ranges.everyItem().appliedConditions,

        i = a.length,

        t, c;

    while( i-- )

        {

        t = conds;

        if( STRICT && t.length != 1 ) continue;

        while( (c=t.pop()) && !(c=c.indicatorColor==uiColor) );

        if( c ) a.remove();

        }

   

})(app.selection[0],UIColors.RED);

@+

Marc

New Participant
May 19, 2023

Marc, we are eight years away from this post but I have some questions. I am new to JavaScript and Indesign scripting in general. When you declared the function at the beginning of you script, the function is:

function removeConditionalText(/*Text*/tx,/*UIColor*/uiColor,/*bool=false*/STRICT


What does /*Text*/tx actually do?

It seems like a paramater, but I do not understand the '/' and the '*'. Are they operators?

Much appreciated, 

Chase

rob day
rob dayCorrect answer
Adobe Expert
May 19, 2023

Hi @Chase29247725h4qr , In case Marc does not see your question /*Text*/ is an efficient way of commenting on the parameters—tells you the tx parameter needs to be a Text object. You could also write comments above the function, depends on your coding preferences, might be something like this where the comments are in green. Code between /* and */ gets commented out: