Example 1: I have a script that make a finish floor, but it does not work if the project is set to metric.
Example 2: A script asks the user for a distance, but the prompt and the number depend on the document units… If I write “Enter thickness” without the correct units (“ft”, “inches”, “cm”, etc.) the results will vary with the current doc units settings.
What I had done was a custom node that inspects the current doc units, and returns a numeric factor that I need to multiply any and all distances so that the results are predictable (basically converts everything to inches). Now it does not work anymore because of python 3…
So, again, ho do you guys make sure the units settings of the current doc don’t screw up your graph?
Generally most people don’t. The right way is the unit conversion utilities in the API or the forge unit types in later builds, but most firms I’ve worked at seem to just assume the unit based on their locality and templates.
Personally I use a library in Python to handle units using the above methods when units become relevant in pyrevit, but for Dynamo I just assume the units in most cases unless it’s a heavily used script.
Apologies, I meant this script, but adapted to IronPython3
thank you
import clr
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
import System
doc = DocumentManager.Instance.CurrentDBDocument
result = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length).DisplayUnits
OUT = result
Did you know, there is a NON-ZERO chance that a monkey could type the Constitution by punching a keyboard?
I did it.
I feel like crying.
import clr
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
import System
doc = DocumentManager.Instance.CurrentDBDocument
unit = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
result = LabelUtils.GetLabelForUnit(UnwrapElement(unit))
OUT = result