Friday, April 2, 2010

ApplyConditions ... how to?

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!

ApplyConditions ... how to?

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.

ApplyConditions ... how to?

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

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

A T,

See http://www.kahrel.plus.com/indesign/word_letter_spacing.html for a concrete example. It's in JavaScript, but that's easy to transfer to VB.

Peter

%26gt;You are right about Javascript, it's ''weakly typed''

I've seen the term ''dynamically typed'' used with reference to JavaScript's typing. That could be interpreted as a euphemism or an acknowledgement of a great feature.

Peter

Hi Peter! Still have to thank you for mentioning the JS help in your latest guide (it has its own web page now, a bit easier for the different versions).

... easy to transfer to VB ..

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.

Whoa, good call there Jongware.

Somehow yesterday when I tested this, the eyeball was off. How silly is that!

I've retested this code from above and find that it works! (Just gotta keep the eyeball(s) open. )

Dim oMyConditions as InDesign.Objects

set oMyConditions = oIDApp.CreateCollection( _

?Array(oIDDoc.Conditions(''Condition Name 1''), _

?oIDDoc.Conditions(''Condition Name 2''))

oIDText.ApplyConditions oMyConditions, True

Interestingly enough, this process can be shortcutted even more:

oIDText.ApplyConditions Array(oIDDoc.Conditions(''Condition Name 1'')), True

Thanks for your help!

A T

%26gt;it has its own web page now

Ah, good! Found it and will add it.

Thanks,

Peter

No comments:

Post a Comment