Custom formatting for Detail Scale variable

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:

  1. gets the detail scale from a specified object (so, DetailScale)
  2. 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 to SCALE = 0.76600
  • the equivalent f-string doesn’t work: SCALE = %<f'{1-.234:.5f}'>% evaluates to SCALE = ####
  • 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 to False and %<DetailScale("front_elevation","Noformatting") + 2>% evaluates to #### (%<DetailScale("front_elevation","Noformatting")>% by itself gives 0.071)
  • therefore, even .format() doesn’t work with DetailScale: %<'{:.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.

Hey @defenestrated,

Sorry this slipped thru the cracks.

We’ve never had a request for this type of scale formatting. Where will this be used? Do you have an example where you use this?

It’s currently not possible to add custom Python code in text fields. The only way forward today is to just write a script to format and add the text.

– Dale

Hi @dale,

No worries, thanks for the response!

I work at the intersection of architecture, interior, and product design; we often have to send construction drawings out for fabrication or permitting. The standard (at least among the companies we work with in the Bay Area) for length measurements is feet and inches, so even though 1" = 18" is technically the same, I was hoping for a way to achieve the desired 1" = 1’-6" (rather than 2/3" = 1’-0").

The reasoning behind this, as I understand it, is so that in the field, if you have to measure a drawing with a physical scale, it’s a lot easier to measure inches on the drawing and then multiply by the scale factor than it would be to measure multiples of 2/3", then multiply that by the scale factor.

Here’s an example from one of our CDs (you’ll note that the 04 is off-center, that’s a different problem with the PDF output…):

The scripting piece was just my technologist brain making the leap to “wouldn’t it be cool to have full arbitrary control over text variables” – not just for DetailScale, but, I dunno, page numbers, dimension text, etc. Being able to do regex and perform math on that kind of variable would open up infinite possibilities…