Hello,
I’m trying to display decimal model units as fractional Feet & Inches and mostly there with the the existing method but I would like it to match the formatting of the dimension style in the snipped image.
Please note the hyphen location.
-My preference is the following formatting: 1’ - 3 3/8"
-The current code returns 1’3-3/8"
Perhaps there is a different method but I couldn’t find it if there is.
Graph Space:
Desired formatting:
Code:
import Rhino
model_units = Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem
dim_style = Rhino.RhinoDoc.ActiveDoc.DimStyles.Current
feetInches = Rhino.UI.DistanceDisplayMode.FeetInches
precision = 3
Uf = Rhino.UI.Localization.FormatNumber(U, model_units, feetInches, precision, False)
#Uf = Rhino.UI.Localization.FormatDistanceAndTolerance(U, model_units, dim_style, False)
print(Uf)
FYI:
Here’s what it looks like in context,
I’ll need to expand the code to create a “mask frame” for the text and leverage display pipeline I think but for now this works with the exception of the formatting:
Thanks for the help!
1 Like
I’m not using imperial units all that often but still…
Couldn’t you solve this with an annotation style?
I have not found out how to replace the horizontal line for the fraction display with a slash.
1 Like
Hi @martinsiegrist thanks for your response! Regarding annotation styles, yes and no.
I do have my baked dimensions solved with the annotation styles as you mention. (You can see this in the snip above with the black dimensions)
However, the blue dimensions are dynamic and unbaked, they appear anytime an object is selected, giving a dimension from the object bounds (or center if not 3D) to the nearest objects.
I tried to query the annotation style I created for the baked dimensions but couldn’t get that working in the code either.
As far as the stacking vs. horizontal dimension display, that setting is under the Units Settings and it’s called Fraction Format:
1 Like
Ok, understood.
I’m still missing an option to output the dimension text.
Would be nice if the text overridee output would output the dimension value the way it is displayed, no?
feet_inches_fractional.gh (29.2 KB)
1 Like
I agree, it does if you are connected to existing referenced dimensions like if you use Query Model Objects → Annotations and then hook a panel to the Text Override you get the formatted dimension text as string.
It just appears that this field does not get populated until AFTER the dimensions have been baked.
Maybe it’s complicated under the hood? Maybe it’s not too bad.
Perhaps @AndyPayne can weigh in on the Text Overrides output for referenced dimensions that have yet to be baked?
1 Like
Have you tried the suggestions, or even the code in this older thread?
1 Like
Thanks @James_Parrott those were good to look through, I had not seen that post previously.
While the cluster shared in that post does return the result I am after it is very long/convoluted code wise.
The python script was the direction I was headed initially, formatting within the code using fractions and math but then I remembered the UI methods that @dale has posted in the past and I believe the method needed exists as a single line of code somewhere, specifically for converting from model units to UI readable formatting. I just can’t seem to find the right one.
I did find this method that appears to accept a Dim Style but I can’t seem to actually find a dim style by name.
https://developer.rhino3d.com/api/rhinocommon/rhino.ui.localization