Skip to main content
Participant
June 24, 2009
Answered

ApplyConditions ... how to?

  • June 24, 2009
  • 1 reply
  • 1493 views

So far it seems that the (paragraph, text, word, etc.).ApplyConditions want a "Conditions" object the first parameter. However I'm unsure how to create a "Conditions" object with the specific conditions I want to apply.

Maybe this is off slightly, but I would like to know how to apply text conditions from a script!

Thanks!

This topic has been closed for replies.
Correct answer Jongware

Transferring to Javascript isn't an option, because I'm using VBA behind Excel and Access. It's the only language, whether I like it or not.

The fact that my text disappears when I ApplyConditions is most disconcerting! I do need to get this going in VB.

Thanks!

Tony


Check your Conditions panel. Does it disappear because it's set to invisible?

Also, check what Undo sez. Does it say "Undo Typing"? That would indicate InDesign thinks you entered some new text, deleting what was selected.

1 reply

Jongware
Community Expert
Community Expert
June 24, 2009

Enter my JS Help (http://www.jongware.com/idjshelp.html)

But seriously. Looking up 'condition' shows its parent is either the application, or your document. A double-check in 'Document' shows it has a property 'conditions'. So, presumably (normally I'd check before posting, but I'm at home now) one should add a fresh condition to the document

myCondition = yourDocument.conditions.add();

and set its properties (although that can be done in the add line):

myCondition.name = "hello_kitty";

myCondition.indicatorColor = UIColors.GOLD;

myCondition.visible = false;

Then you (still presumably) can apply it to text:

someText.appliedConditions  = ... "Array of Condition r/w The applied conditions". Hm. Didn't see that one commin'. I'll have to check up on how to do this last part. That's what happens when typing-while-thinking.

[Edit] OK, 5 sec and a quick refresh later. Yeah, it's "someText.applyConditions (using:Array of Conditions])". So (still presumably), this oughta do it:

someText.applyConditions ([myCondition]);

Well, for JavaScript it oughta, your capital A suggests you are using VB.

A_T_JonesAuthor
Participant
June 24, 2009

I've tried a number of different arrays. Perhaps the more-or-less un-typed Javascript is more forgiving, but I'm coding in VB.

The following code fails because c is not the correct type.


Dim c(1) as InDesign.Condition     'Array of Condition

set c(0) = oIDDoc.Conditions("Condition Name 1")

set c(1) = oIDDoc.Conditions("Condition Name 2")

oIDText.ApplyConditions c, True

So a strict array of Conditions is no good.

I was able to create something that compiles following way:

Dim c as InDesign.Objects

set c = oIDApp.CreateCollection( _

    Array(oIDDoc.Conditions("Condition Name 1"), _

    oIDDoc.Conditions("Condition Name 2"))

oIDText.ApplyConditions c, True

Looks good, compiles. Indicates this could be a "right" way to do it.

But has a very bad effect. Any Text, Paragraph, or anything else I apply it to looses all of its text. Kind of useless? Or is that "by design" for some reason that escapes me?

Incidentally

myParagraph.AppliedConditions.Add oIDDoc.Conditions("Condition Name 2")

has no apparent effect.

Is this just a total flop on Adobe's part and is completely nonfunctional/broken? Or am I missing something?

A T

Jongware
Community Expert
Community Expert
June 24, 2009

You are right about Javascript, it's "weakly typed". And I'm not really a VBS guy.

I would guess your first sample fails because the new conditions have to be added to either your document or the application itself. It seems that your second try adds them to the application, making them available for all new documents as well -- perhaps that's not what you want :-)

Going out on a limb: since you create a new condition, perhaps those are initialized to all zero's -- setting its "visible" property to false as well, which may explain why the text disappears ... you can check this in your Conditions panel and in the Story Editor. (It might also explain why straight out applying an existing condition doesn't "do" anything. But purely that's conjecture on my side -- I'd have to try it first myself.)