I would like to use a ceiling text macro in my room labels to display the height, but it displays fractions, which aren't desired. How can I make it so that the height is rounded, either to the nearest inch or to the nearest foot?
By default, many text macros are setup to display the raw, unrounded results of the calculation they perform, but you can easily create a macro that rounds to the nearest value of your choosing using the information in this article.
Note: If you would like custom text macros to be present in all files that you create, consider making the changes below to your template(s). For more information on templates, please see the Related Articles section below.
obj = owner
obj = referenced unless referenced.nil?
nf = NumberFormatter.new
nf.unit = "'-\""
nf.use_fractions = true
nf.denominator = 1
nf.apply(ceiling_height)
nf.apply
property, the value will be in feet and fractional inches per the nf.unit
and nf.use_fractions
properties, but the resulting value will round fractions up to the nearest whole number per the nf.denominator
property. If you wanted to round to the nearest 1/4", you can replace the number 1 with the number 4. Using the code mentioned above, our ceiling height will now display as 9'-1" when this text macro is used. nf.unit
property to "'"
so only feet are displayed. Note: If a room is not selected prior to accessing the Text Macro Management dialog as mentioned in Step 2 above, the Original Result and New Result fields in the Edit Text Macro dialog will instead display with Evaluation Errors. This does not mean the macro will not function correctly when used, just that it can't perform the function as an applicable room was not selected.
%CeilingHeightRounded%
, which is the name of the macro we just created.Note: If automatic room labels have already been populated prior to creating and inserting a macro, the labels may need to be refreshed. This can be done by opening one or more rooms up to specification, making a change to the Room Type or Room Name, then clicking OK. Once the room labels have been refreshed, you can revert the change made to the Room Type or Room Name.
The room's label will now display, along with the ceiling height of the room rounded to your preference.
You can now apply these same concepts to other custom macros to achieve similar results.