my code below:
test= 1
runs[2].LookupParameter('Extend Below Riser Base').Set(test)
Result:
How to avoid revitapi to auto convert the length?
my code below:
test= 1
runs[2].LookupParameter('Extend Below Riser Base').Set(test)
Result:
How to avoid revitapi to auto convert the length?
my current unit is sometimes millimeter or meter depends on project, dividing 304.8 is not always correct.
You can look up the project units for a specific unit type, Length in the code below, and use that to determine the conversion needed.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
unitType = UnitType.UT_Length
currentDisplayUnits = doc.GetUnits().GetFormatOptions(unitType).DisplayUnits
OUT = currentDisplayUnits
thank you!
and I found that your code is for revit 2021 and previous,
I need a different one if using revit 2022
You need SpecTypeId
instead of UnitType
because of a change in the API between 2021 <->2022:
if int(DocumentManager.Instance.CurrentUIApplication.Application.VersionNumber) < 2021:
factor = UnitUtils.ConvertToInternalUnits(304.8,doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits)
else:
factor = UnitUtils.ConvertToInternalUnits(304.8,doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId())
Here another example:
if int(DocumentManager.Instance.CurrentUIApplication.Application.VersionNumber) < 2021:
unit = famdoc.GetUnits()
currectformat = doc.GetUnits().GetFormatOptions(UnitType.UT_Length)
accuracy = currectformat.Accuracy
unit.SetFormatOptions(UnitType.UT_Length,FormatOptions(currectformat.DisplayUnits,accuracy))
famdoc.SetUnits(unit)
else:
unit = famdoc.GetUnits()
currectformat = doc.GetUnits().GetFormatOptions(SpecTypeId.Length)
unit.SetFormatOptions(SpecTypeId.Length,currectformat)
famdoc.SetUnits(unit)
thank you!