Skip to main content
Inspiring
May 19, 2014
Answered

How to create and apply a condition to selected text?

  • May 19, 2014
  • 1 reply
  • 1583 views

Hi All,

I am new to InDesign scripting. I am using Flex 4.6, so I am using ActionScript. I want to apply conditional texts to some selected texts in my document. I understand the process manually. But am having problem doing it programmatically.

I see that there is a Condition class. I created an object of this class and tried to assign some values.

var nameCondition = new Condition();

nameCondition.indicatorMethod = ConditionIndicatorMethod.USE_UNDERLINE;

nameCondition.label = "Name";  // Couldn't understand what label stands for

nameCondition.name = "Name"; 

nameCondition.visible = false;

Now, when I debug, I see that the values that I assigned to nameCondition object are never assigned.

I also came across the appliedConditions method that is available in the app and doc levels. But, I am not sure how to use it.

Please help.

This topic has been closed for replies.
Correct answer csm_phil

Hi poortip87,

Find the below JS code, its working InDesign CS5.5 only.

var myDoc = app.activeDocument;

try{

    myDoc.conditions.add({name:"TEST", indicatorColor:UIColors.GOLD, indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, visible:false})

    }catch(e){}

   

   

app.selection[0].applyConditions(myDoc.conditions.itemByName("TEST"));

thx,

csm_phil

1 reply

csm_phil
csm_philCorrect answer
Braniac
May 19, 2014

Hi poortip87,

Find the below JS code, its working InDesign CS5.5 only.

var myDoc = app.activeDocument;

try{

    myDoc.conditions.add({name:"TEST", indicatorColor:UIColors.GOLD, indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, visible:false})

    }catch(e){}

   

   

app.selection[0].applyConditions(myDoc.conditions.itemByName("TEST"));

thx,

csm_phil

poortip87Author
Inspiring
May 20, 2014

Hi Phil,

Thanks for the prompt reply! I tried your code for CS6 and was able to create a new condition.

But unable to apply the condition to selected text. Working on that. Will get back if I have success!

Thanks!

poortip87Author
Inspiring
May 20, 2014

I was able to fix this..

applyCondition expected an array as parameter, so I gave it one.

var arrCond:Array = new Array();

arrCond.push(app.activeDocument.conditions.item("Name"));

app.selection[0].applyConditions(arrCond, true);

Thanks to Phil, I can move forward now!