Query all Project Units

Hello all,

I am attempting to query all of the display units in this Revit file (Length = Feet and Fractional inches, Area = Sq. Ft.). I’ve found a node from GeniusLoci that outputs all of the Unit Types and a python script to get the display units, but for one unit type. The issue I assume I’m running into is a conversion error. Here is a screengrab of my graph and my python script.

Cheers,

import clr
 
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc =  DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
 
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
 
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
 
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *

import System
from System.Collections.Generic import *
# The inputs to this node will be stored as a list in the IN variables.
unT = UnwrapElement(IN[0])
result = []
# Place your code below this line
for i in unT:
	cool = Document.GetUnits(doc).GetFormatOptions(UnitType.i).DisplayUnits
	result.append(cool)
# Assign your output to the OUT variable.
OUT = result

Hi @patrick_podeyn,

I think the node you are looking for already exists in the latest versions of the Genius Loci package. :grinning:

You can modify your script like this :

import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc =  DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
 
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
 
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
 

unT = UnwrapElement(IN[0])
result = []
# Place your code below this line
for i in unT:
	cool = Document.GetUnits(doc).GetFormatOptions(i).DisplayUnits
	result.append(cool)
# Assign your output to the OUT variable.
OUT = result

Project units2

3 Likes

Thanks! Yeah, I wanted to get this to work in Python purely for learning. It’s nice to know I wasn’t off by much. So, how come I don’t need to put (UnitType.i) and what does the error ‘type’ object has no attribute ‘i’ mean?

Thanks!