Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Delete conditional text

Engaged ,
Oct 05, 2015 Oct 05, 2015

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

982

Likes

Translate

Translate

Report

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

Guide , Oct 05, 2015 Oct 05, 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;    ...

Likes

Translate

Translate
Guide ,
Oct 05, 2015 Oct 05, 2015

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Oct 05, 2015 Oct 05, 2015

Copy link to clipboard

Copied

Or maybe just this:

app.findGrepPreferences = app.changeGrepPreferences = null;

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

app.selection[0].changeGrep();

Peter

Likes

Translate

Translate

Report

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
Guide ,
Oct 05, 2015 Oct 05, 2015

Copy link to clipboard

Copied

Maybe 😉

@+

Marc

Likes

Translate

Translate

Report

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
Engaged ,
Oct 05, 2015 Oct 05, 2015

Copy link to clipboard

Copied

Both working fine for me . Thanks lot.

Likes

Translate

Translate

Report

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
New Here ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

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?

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
New Here ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

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.

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Until you get the script working, you can do a Find/Change for the condition and replace it with nothing. Then delete the condition. 

 

Aside: I could have sworn ID used to give a dialog box asking about what to do with the applied conditional text when you delete a condition. I know FrameMaker does. 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

To delete just the conditions in all open documents and leave intact the texts to which it applied, use this:

for (i = 0; i < app.documents.length; i++) {
  if (app.documents[i].conditions.item('red').isValid) {
    app.documents[i].conditions.item('red').remove();
  }
}

P.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

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 )

Likes

Translate

Translate

Report

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
New Here ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Thank you very much, this was very helpful.

 

Likes

Translate

Translate

Report

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
New Here ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

LATEST

Sure:

for (i = 0; i < app.documents.length; i++) {
  if (!app.documents[i].conditions.item('red').isValid) {
    app.documents[i].conditions.add({name: 'red'});
  }
}

Likes

Translate

Translate

Report

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