R8 - GH - Convert Units Component - Fractional Inches?

Hello,

The new Convert Units component is great but it appears to only support decimal inches.

Am I overlooking something or is their support for return the Target units as Fractional Inches and Fractional Feet & Inches Unit Systems?

@kike @AndyPayne

Decimal inches is nice but for US based Architectural drawings we tend to show fractions.

Thanks for the insight!

The component is just doing the unit conversion but not formatting on any way.
In fact it returns a number and then is Grasshopper who formats this number in the text panel.
Are you looking for a component that formats lengths?
What about areas, volumes??

I see, that makes sense!

Ideally yes, I would make extensive use of a component handling the formatting as well.

So for example if the area/volume components return the default values in decimal model units, I would love to have a component I could add after this that would accept formatting like “Sq. Ft.” or “FT2” (with the superscript small 2 after T"

I realize I can simply use concatenate to manually add such text (which is what I have been doing) but in cases such as the snip I provided where we end up with decimal model unit values (feet in this case) such as 1.5 or 9.75, I would love to be able to set the formatting to “Fractional Feet & Inches” and have the values be returned formatted as 1’ - 5" or 9’ - 9" respectively.

I actually have a Python script I spent a lot of time building that parses “messy” strings like 9’ 10.75cm or 10’-7" or 187cm 3/4" and returns the decimal model unit value of said user input “messy” strings.

I just don’t have something to go in the reverse order from model units to fractional display.

If I recall, some of these formatting choices are exposed with dimension text settings and I’m wondering if this could be extended to the text settings component in general? Like decimal vs. fractional display representation of values, fractional stacking, 0 suppression, etc.

Also I think @dale shared some code a ways back that was a UI method in the API documentation that specifically formatted values as I’m mentioning but I can’t seem to find that code now.

Thanks for your help, I’m sure you have better ideas on how to implement such a thing and where it would live component wise.

@michaelvollrath - maybe this?

1 Like

That’s the one, thank you @dale!

EDIT:

Here’s the code I’m working with based off of what you shared.
Is there a reason why longer decimal values do not get a hyphen between the feet and inches where as the shorter decimal values do?

Code:

import Rhino

model_units = Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem

feetInches = Rhino.UI.DistanceDisplayMode.FeetInches
precision = 4

Fv = Rhino.UI.Localization.FormatNumber(V, model_units, feetInches, precision, False)

You can reproduce this with the following input values:

2.333333
6.75
0.125
2.666667
6.75
0.125
2.333333
6.75
0.125
2.333333
6.75
0.125
2.333333
6.75
0.125
4
6.75
0.125
2.666667
6.75
0.125
2.666667
6.75
0.125
2.333333
6.75
0.125
2.666667
6.75
0.125
2.666667
6.75
0.125
2.666667
6.75
0.125
16
8
0.125
2.666667
8
0.125
2.666667
8
0.125
3
6.75
0.125
3
6.75
0.125
15.833333
10
0.125
2.666667
8
0.125
2.666667
6.75
0.125
2.666667
6.75
0.125
2.666667
8
0.125
2.666667
8
0.03125
2.666667
6.75
0.125
3
6.75
0.125

Results With Missing Hyphens:

2'4"
6'-9"
1-1/2"
2'8"
6'-9"
1-1/2"
2'4"
6'-9"
1-1/2"
2'4"
6'-9"
1-1/2"
2'4"
6'-9"
1-1/2"
4'-0"
6'-9"
1-1/2"
2'8"
6'-9"
1-1/2"
2'8"
6'-9"
1-1/2"
2'4"
6'-9"
1-1/2"
2'8"
6'-9"
1-1/2"
2'8"
6'-9"
1-1/2"
2'8"
6'-9"
1-1/2"
16'-0"
8'-0"
1-1/2"
2'8"
8'-0"
1-1/2"
2'8"
8'-0"
1-1/2"
3'-0"
6'-9"
1-1/2"
3'-0"
6'-9"
1-1/2"
15'10"
10'-0"
1-1/2"
2'8"
8'-0"
1-1/2"
2'8"
6'-9"
1-1/2"
2'8"
6'-9"
1-1/2"
2'8"
8'-0"
1-1/2"
2'8"
8'-0"
0-3/8"
2'8"
6'-9"
1-1/2"
3'-0"
6'-9"
1-1/2"

It appears that If I round to 3 decimal places, the hyphen will show up:

2'4"
6'-9"
1-1/2"
2'-8"
6'-9"
1-1/2"
2'4"
6'-9"
1-1/2"
2'4"
6'-9"
1-1/2"
2'4"
6'-9"
1-1/2"
4'-0"
6'-9"
1-1/2"
2'-8"
6'-9"
1-1/2"
2'-8"
6'-9"
1-1/2"
2'4"
6'-9"
1-1/2"
2'-8"
6'-9"
1-1/2"
2'-8"
6'-9"
1-1/2"
2'-8"
6'-9"
1-1/2"
16'-0"
8'-0"
1-1/2"
2'-8"
8'-0"
1-1/2"
2'-8"
8'-0"
1-1/2"
3'-0"
6'-9"
1-1/2"
3'-0"
6'-9"
1-1/2"
15'10"
10'-0"
1-1/2"
2'-8"
8'-0"
1-1/2"
2'-8"
6'-9"
1-1/2"
2'-8"
6'-9"
1-1/2"
2'-8"
8'-0"
1-1/2"
2'-8"
8'-0"
0-3/8"
2'-8"
6'-9"
1-1/2"
3'-0"
6'-9"
1-1/2"

Is that a bug, floating point precision, or am I missing something?

Thanks for your help!