# Text Field Arithmetic - Divide Point Coordinate by 1000

G’day,

How can I perform some basic arithmetic of dividing the Z coord result from a point coordinate text field by 1000? That sentence is a bit convoluted, field is below.

%<PointCoordinate(“19067630-7c14-4b72-bb53-9689f0b5672f”,“Z”)/1000>%

Something very weird is going on.
Text field on its own works as expected.

Division fails - Text object is hashed out

Addition fails - Text object is hashed out
Multiplication fails - see screenshot

This seems to be a string multiplication (2235.915 repeated 1000 times) rather than an arithmetic operation.

cheers,
Nick

Hi Nick - yep, I do not think there is any provision for that - I do not know that there could not be, but as far as I know it is not.

-Pascal

Internally PointCoordinate is a function that returns a string which I think may be a bug. @Trav and I will need to dig in little deeper to figure out if this really is the case and if it can be modified.

Since the function returns a string, you would currently need to convert that string back into a number for math to be performed on it. This would require placing PointCoordinate inside a float function to go from string to number.

%<float(PointCoordinate(“19067630-7c14-4b72-bb53-9689f0b5672f”,“Z”))/1000>%

1 Like

Yeah it does some string formatting for displaying “X,Y,Z” if all three are checked but I am sure we can either add some overloads for different options or come up with something easier out of the gate. I’ve made a YT for it here so we can make sure to take a look.

https://mcneel.myjetbrains.com/youtrack/issue/RH-64016

Thanks for looking at this. The float conversion from string works well and I’d be happy for it to be the final solution. It might be confusing to alternately return strings or floats from the same text field.

Is this a standard Python function? Perhaps an amendment to the help would be sufficient.

cheers,
Nick

Hi Nick -

Float conversion doesn’t only apply to the `PointCoordinate` text field.
Further up on that page, you will find this section:

… where the “How to…” links to the “Convert strings to numbers” page.

Obviously, it’s not 100% discoverable but I’m not sure if that should be repeated for each text field on that page that returns a string that could be a number…
Perhaps that part should be moved to the “Math Support” section a bit further up?
-wim

My hope is we can eventually provide a simple formula editor for these text fields with features that would make this easier.

2 Likes

Ah, that’s where it is. Honestly, I was looking for something similar.

Agree.

Alternatively, perhaps document as per script functions and state the data type that is returned by each field.
Area (returns a Float)
Length (Float)
Coordinates (List of Strings or Single String)
BlockInstanceCount (Integer)
etc

Nick

Very useful, is there any way to change number of decimal places? wrapping `PointCoordainte` with `float` gave me two decimal digits, but I’m trying to get three.

Hi Daniel -

This is beyond my level of comfort but it seems to work…

1. You first have to set your `Document Properties -> Units -> Distance display -> Display precision` to `1.000`.
Note - if you don’t need to divide your result with 1000, that first step will suffice.

2. Then, add formatting to the string. According to the help file, both Python and .NET formatting can be used. Some trial-and-error shows that the following complete expression works fine:

%<‘{:0}’.format(float(PointCoordinate(“585e44d0-d1d1-4169-ac13-b28140285a1b”,“Z”))/1000)>%

-wim

1 Like

Thank you, that’s really helpful, but for some reason it yielded four decimal places, not three. Replacing `{:0}` with `{}` yielded five, but I couldn’t get three

This will give you three decimals (using Python-style formatting):

``````%<format(float(PointCoordinate(“585e44d0-d1d1-4169-ac13-b28140285a1b”,“Z”))/1000,"+0.3f")>%m SITE LEVEL
``````

HTH
Jeremy

3 Likes

Perfect, that works like magic for me. And changing `0.3f` adjusts number of digits.