A while back, we demonstrated how to do so in C#. In this post, let’s provide the VB.NET version of the code.
To recap a bit, calling the Document.DisplayUnitSystem property against the Family Document is the way. It will tell us if the Family has been created from an Imperial or Metric unit system.
Here is the handy help method in VB.NET:
Public Shared Function FromImperialOrMetric(doc As Document, id As ElementId) As DisplayUnit
Dim ret As DisplayUnit = DisplayUnit.IMPERIAL
Dim instance As FamilyInstance = DirectCast(doc.get_Element(id), FamilyInstance)
Dim family As Family = instance.Symbol.Family
Dim famDoc As Document = doc.EditFamily(family)
ret = famDoc.DisplayUnitSystem
Return ret
End Function
Here is the test code:
Dim picked As Reference = CachedUiApp.ActiveUIDocument.Selection.PickObject(ObjectType.Element, "Pick any family instance")
Using trans As New Transaction(CachedDoc, "FromImperialOrMetric")
trans.Start()
MessageBox.Show(FromImperialOrMetric(CachedDoc, picked.ElementId).ToString())
trans.Commit()
End Using
So again, the key point is the ‘Family Document’, which has to be retrieved from the EditFamily() call. If we use the Document property of the Family object directly, it will return the Display Unit of the host document that is visible and editable in your Revit window. It is surely confusing, but that is the world.
Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.
Recent Comments