Retrieve units from links

Hi all

I’m trying to retrieve the units in use in the linked documents. I will like to use a federated RVT model with several links (up to 20 in some cases) to do some basic fast check before the submissions to the client.
The requirement is to submit the model in “Meter” units for “Length”. I’m trying with the GeniusLoci “Document Units” custom node, feeding with Link Doc and Link Instance with no luck.
I know that some of the links are in centimetres or inches (I’ve edited them for testing purpose) but the result is always Meters.

Is there other way to show this information in dynamo?

Kind regards

Here’s some python to achieve what you are after

import sys

import clr

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import FilteredElementCollector, RevitLinkInstance, SpecTypeId, UnitUtils

doc = DocumentManager.Instance.CurrentDBDocument

revit_links = FilteredElementCollector(doc).OfClass(RevitLinkInstance)
length = SpecTypeId.Length

# Helper function
def get_unit_type(link, spec):
    link_doc = link.GetLinkDocument()
    units = link_doc.GetUnits()
    unit = units.GetFormatOptions(spec).GetUnitTypeId()
    return link_doc.Title, UnitUtils.GetTypeCatalogStringForUnit(unit)

OUT = [get_unit_type(link, length) for link in revit_links]

Also check your list level on the Document Units node
image

Hi Mike.Buttery
The python script you provided works flawless.
The addition of the document name is also a great touch (I’m hiding it for safety reasons):

I’ve checked the levels in the Document Units node but the result is the same as before, it shows the units of the active document and not the links as in the script you provided:

Thank you Mike for your help! It will save me lots of hours of open-check-close models.

1 Like