Skip to main content
Trevor:
Legend
August 2, 2011
Answered

Returning a conditional text value.

  • August 2, 2011
  • 1 reply
  • 9799 views

Hi,

Can somebody tell me how to get the conditional text name (if there is) of the insertion point.

Something like.

CondintionalTextName=insertionpoint.conditional.name

but written in Java Script instead of Gibberish!

This topic has been closed for replies.
Correct answer Marc Autret

Hi Trevor,

Probably sth like:

ConditionalTextName=insertionpoint.appliedConditions[0].name;

Note that appliedConditions is an array, because multiple conditions can be applied to the same text.

EDIT—To avoid errors with non-conditional text:

var conds = myText.appliedConditions;

var condName = conds.length ? conds[0].name : '[No Condition]';

@+

Marc

1 reply

Marc Autret
Marc AutretCorrect answer
Legend
August 3, 2011

Hi Trevor,

Probably sth like:

ConditionalTextName=insertionpoint.appliedConditions[0].name;

Note that appliedConditions is an array, because multiple conditions can be applied to the same text.

EDIT—To avoid errors with non-conditional text:

var conds = myText.appliedConditions;

var condName = conds.length ? conds[0].name : '[No Condition]';

@+

Marc

Trevor:
Trevor:Author
Legend
August 22, 2011

Hi Marc,

Thanks for your answer, sorry for the long delay in my response .  I had a couple of things to iron out (like how to return all the conditions for all the selected texts and other simple issues that I'm too embarrassed to write) and I have been exceptinaly busy with other things.

This is the code that I came up with based on your answer.

try {
var cl=app.selection[0];
var w = new Window ("dialog","");
array = [];
for (var j = 0; cl.length>j; j++){
    var conds=app.selection[0].characters.appliedConditions;
    var curletter=app.selection[0].characters.contents;
   
for (var i = 0; conds.length > (i); i++) {

array.push ("Letter "+(j+1)+" \""+curletter+"\""+"\tCondition "+i+" name is \t"+conds.name+" ");}
if (conds.length==0) {
var condName = conds.length ? conds[0].name : '[No Condition]';
array.push ("Letter "+(j+1)+" \""+curletter+"\""+"\tCondition "+i+" name is \t"+condName)
}
}
if (j==0){var i=0;}
array.push ("\r\tSelected text \""+app.selection[0].characters.itemByRange(0,-1).contents+"\"");
array.push ("\tIn total "+j+ " characters");
alert_scroll ("Conditional Texts Names of Selectect Characters", array,);
function alert_scroll (title, input) // string, string/array
{
// if input is an array, convert it to a string
if (input instanceof Array)
input = input.join ("\r");
var w = new Window ("dialog", title);
var list = w.add ("edittext", undefined, input, {multiline: true, scrolling: true});
// the list should not be bigger than the maximum possible height of the window
list.maximumSize.height = w.maximumSize.height - 300;
list.minimumSize.width = 450;
w.add ("button", undefined, "Close", {name: "ok"});
w.show ();   
}}
catch (cl)
{
    alert("First Select Text!");
}

It produces the following result:

I would like to know two more things about conditionals texts.


1) I would like to add a line at the bottom stating how many DIFFERENT conditions are used throughout all the selected texts. In the above example including [no condition] a total of 8 conditions are used 1) AppleScript 2) blue 3) Green 4) Nikud 5) Red 6) Violet 7) Yellow 8) No condition


2) To apply the "Red" condition to the selected text I would use

app.selection[0].applyConditions ( app.activeDocument.conditions.item("Red", true), true);

I can't figure out how to make the selection have no conditions

app.selection[0].applyConditions ( app.activeDocument.conditions.item("[Unconditional]", true), true); Does not work.


Any Ideas?

Inspiring
June 12, 2012

Trevor, I don't know, if it helps after such a long time ...

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

Tobias