Hi all,
Wondering if there’s a way to add support for more customized formatting (or more generalized python code) within a text field. Specifically, I’m trying to add a text field that:
- gets the detail scale from a specified object (so,
DetailScale
) - formats the scale in the form
1" = 4'-2-1/4"
(or whatever).
There are formats that are close, but none preserve the 1" on the left side. For example,
%<DetailScale("front_elevation","1=#")>% | %<DetailScale("front_elevation","#=1-0")>%
results in:
1" = 1.167' | 7/8" = 1'-0"
In this case, what I want is 1" = 1'-2"
I’ve explored python string formatting, and it seems to me that if one of the “text fields” were “arbitrary python code,” one might be able to do this. Some things I’ve noticed:
-
.format()
works with numbers:SCALE = %<'{:.5f}'.format(1-.234)>%
evaluates toSCALE = 0.76600
- the equivalent f-string doesn’t work:
SCALE = %<f'{1-.234:.5f}'>%
evaluates toSCALE = ####
-
DetailScale
isn’t returning a number, even with"Noformatting"
– meaning one can’t then do math on it:%<isinstance(DetailScale("front_elevation","Noformatting"), (int, float, complex))>%
evaluates toFalse
and%<DetailScale("front_elevation","Noformatting") + 2>%
evaluates to####
(%<DetailScale("front_elevation","Noformatting")>%
by itself gives0.071
) - therefore, even
.format()
doesn’t work withDetailScale
:%<'{:.5f}'.format(DetailScale("front_elevation","Noformatting"))>%
gives####
.
Is there a way to somehow encapsulate custom code, or add new formats to the available options? It’d be awesome to be able to use arbitrary rhinopython code in text fields.
1 post - 1 participant