cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
GDL
About building parametric objects with GDL.
SOLVED!

Rounding in STR{2}

Alex C
Booster

Hi, I've been trying to write some GDL to display an X and Y value as decimal feet, rounded to .5' So for example it would read as "20'x15.5'"

 

The closest I have been able to get is using the below

 

dimxy = STR{2}("%~.1df", A)+"x"+STR{2}("%~.1df", B)
 
This hides the zero for me but I can't for the life of me get it to also round to the nearest .5. I see there is a rounding function in the reference guide but it says that it is for area calculations, these are length. Is this possible or should I be going about this another way?
MAC OS Monterey AC27
2 ACCEPTED SOLUTIONS

Accepted Solutions
Solution
Jochen Suehlo
Moderator

I am not at home in feet and inch, but you could try to round the meter-Values after convert into feet.

A_final = INT(A / 0.3048 * 2 + 0.5) / 2 * 0.3048
B_final = INT(B / 0.3048 * 2 + 0.5) / 2 * 0.3048

dimxy = STR{2}("%~.1df", A_final) + "x" + STR{2}("%~.1df", B_final)

 

Jochen Suehlo . AC12-29 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de

View solution in original post

Solution

Hi Alex,

 

Yeah that rounding to .5 doesn't seem to work for decimal feet.

 

I had a similar idea like Jochen, but different approach:

1. calculate the value of A & B in feet

2. now use the rounding to .5 as if was meters

f2m = 0.3048
fA = A / f2m
fB = B / f2m
dimxy = STR{2}("%*5~.1m", fA)+"x"+STR{2}("%*5~.1m", fB)
text2 0, 0, dimxy
Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com

View solution in original post

3 REPLIES 3
Solution
Jochen Suehlo
Moderator

I am not at home in feet and inch, but you could try to round the meter-Values after convert into feet.

A_final = INT(A / 0.3048 * 2 + 0.5) / 2 * 0.3048
B_final = INT(B / 0.3048 * 2 + 0.5) / 2 * 0.3048

dimxy = STR{2}("%~.1df", A_final) + "x" + STR{2}("%~.1df", B_final)

 

Jochen Suehlo . AC12-29 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de
Solution

Hi Alex,

 

Yeah that rounding to .5 doesn't seem to work for decimal feet.

 

I had a similar idea like Jochen, but different approach:

1. calculate the value of A & B in feet

2. now use the rounding to .5 as if was meters

f2m = 0.3048
fA = A / f2m
fB = B / f2m
dimxy = STR{2}("%*5~.1m", fA)+"x"+STR{2}("%*5~.1m", fB)
text2 0, 0, dimxy
Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com
Alex C
Booster

Thanks guys, both methods work great.

 

I don't totally understand the math for you method Jochen, It seems more like the meter values are being rounded before being converted to feet? For the other method I did have to add the foot tick mark into the string since it won't display for the meter conversion value.

MAC OS Monterey AC27

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!