# Formulas in Data Tags

## Recommended Posts

The short version of what I'm trying to accomplish is to show the absolute value of a coordinate in a data tag (for instance, if the coordinate is -20'0" on the X axis, I just want it to say 20'0"). I'm essentially dimensioning from a 0,0 point and the direction (which would be expressed as positive/negative) is irrelevant.

I do this in worksheets with a simple if/else formula: =IF((XCOORDINATE>0), XCOORDINATE, -(XCOORDINATE)) because I haven't run across an easier way. Some spreadsheets have an ABS(value) function, but I don't see this in VW.

My questions are:

- is it possible to put a a formula such as this in a data tag? I haven't had any luck, it just displays as text, but maybe I don't have the right syntax.

- either way, is there an easier way to get the figure I'm looking for?

Thanks,

Brian

XCOORDINATE does not exist in Data Tags, but the object insertion point of the Data Tag does using a tag of #IPX#.

IF/Then is weird in Data Tags. It uses a formula of

<Value_If_True>@<The_Condition>:<Value_If_False>. Don't use any spaces between things.

So I think the following will give you what you want:

-#IPX#@#IPX#<0:#IPX#

Thank you to @michaelk for helping me refine this syntax.

Ask again if you need more help.

1 hour ago, Pat Stanford said:

IF/Then is weird in Data Tags. It uses a formula of

<Value_If_True>@<The_Condition>:<Value_If_False>. Don't use any spaces between things.

You're kidding me.

That is the only format I have been able to make work in VW2021.

I'm sure your right, but that sort of syntax is supposed to entice users who are avoiding using vectorscript, python, or marionette?  It seems like they have given users access to a tool that they will use to fashion user requested labeling functionality.  I am consistently impressed by users who dig in to create their own custom solutions, so perhaps there will be a plethora of user data tag solutions.  It's easier for me to deal with vs.  I wonder why they didn't try to stay consistent with worksheet syntax.

My guess is that this is the syntax used by whatever parser they are using under the hood and they didn't have time to wrap it in something better. This is actually very close to a standard Python if then construct which could be like:

<Value if True>?<The Condition>:<Value if False>

They probably changed to @ because the question mark was being used for something else.

I believe/hope that it will be better in future versions, but at least it works in VW2021.

And I completely agree with you that it is almost unusable for anyone not familiar with programming. Or having a friend on the forum who likes digging into obscure questions. 😉

Thanks for this Pat. I've been trying to do an IF/THEN in a data tag for a while and this works for me too! Now if I can only round off a calculated value to one decimal place in a data tag...any thoughts there?

40 minutes ago, Pat Stanford said:

This is actually very close to a standard Python

For me, another reason to stay with VS.

Out of curiosity only.

If the condition cannot be evaluated does the parser capture for processing either the true or false value?; or throw an error dialog or a null value?

The way it is written reminds me of a process without error checking. If read left to right it would capture the false value into the register then process the condition where by a true result would overwrite the register value with the next value to the left. (APL processed code lines left to right)

Where as Pascal or Basic+ type of formatting will have the condition for evaluation first resulting in selectively choosing to ignore either the first value or the second value and do a single write to the register. Hmmm. Overly simplified of course. hehe

I have no idea what is going on under the hood or if there is any error checking.

Since the middle has to be a boolean value, I would assume that there will always be a result from the operator. But will it default to True or False?

It changed in 2019 or 2020.  @ used to be not a reserved character.  I'm looking through the help documents and I can't find it anymore, but there used to be 2 syntaxes for IF/THEN/ELSE statements in data tags.  The only one that I ever got to work (and even that only recently) is result@logic_statement:else

Like Pat said: No spaces to make it more readable 🙂.  I'm not positive about double quotation marks or single quotation marks.  I know I successfully use

#record#.#field#@#record#.#field#<>'':#record#.#differentfield#

The single quotes next to each other recognize a blank field, but all the examples of returning specific text uses double quotes.

@michaelk If it's bugging you 😋, there's a link to the help documents regarding this topic in the following post, but, as we've all mentioned, the @ syntax is the one that works.

Thanks @Eliot Hartzler.  It was bugging me!

Thank you all - and I swear I searched the help before asking. I see it now and it works (using the @ version).

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• KBASE
• #### MARIONETTE

×
• Create New...