Revit window elements do not have a class name designated for them in the Revit .NET API, so we have to use some other means such as their Category name or better ID to identify them when necessary.
In this article, let us see if there are any other means, good or bad, old or new, obsolete or still valid, long or short, popular or rare used, for Revit Window identification purpose. Though it does not have an API class, it has a lot of names and ids actually besides the popularly used, category name/id.
Here is some code to help us to sort it out.
Reference picked = CachedUiApp.ActiveUIDocument.Selection.PickObject(ObjectType.Element, "Pick a window");
FamilyInstance win = (FamilyInstance)CachedDoc.get_Element(picked.ElementId);
string winInfo = "Window Identification:\n";
winInfo += string.Format("\tElement Id: {0}\n", win.Id);
winInfo += string.Format("\tUnique Id: {0}\n", win.UniqueId);
winInfo += string.Format("\tAssembly Instance Id: {0}\n", win.AssemblyInstanceId);
winInfo += string.Format("\tType name: {0}\n", win.GetType().Name);
winInfo += string.Format("\tType full name: {0}\n", win.GetType().FullName);
winInfo += string.Format("\tCategory name: {0}\n", win.Category.Name);
winInfo += string.Format("\tCategory Id: {0}\n", win.Category.Id);
winInfo += string.Format("\tSymbol name: {0}\n", win.Symbol==null?"N/A": win.Symbol.Name);
winInfo += string.Format("\tSymbol Id: {0}\n", win.Symbol == null ? "N/A" : win.Symbol.Id.ToString());
winInfo += string.Format("\tObjectType name: {0}\n", win.ObjectType == null ? "N/A" : win.ObjectType.Name);
winInfo += string.Format("\tObjectType Id: {0}\n", win.ObjectType == null ? "N/A" : win.ObjectType.Id.ToString());
winInfo += string.Format("\tHost name: {0}\n", win.Host == null ? "N/A" : win.Host.Name);
winInfo += string.Format("\tHost Id: {0}\n", win.Host == null ? "N/A" : win.Host.Id.ToString());
winInfo += string.Format("\tGroup name: {0}\n", win.Group == null ? "N/A" : win.Group.Name);
winInfo += string.Format("\tGroup Id: {0}\n", win.Group == null ? "N/A" : win.Group.Id.ToString());
winInfo += string.Format("\tSpace name: {0}\n", win.Space == null ? "N/A" : win.Space.Name);
winInfo += string.Format("\tSpace Id: {0}\n", win.Space == null ? "N/A" : win.Space.Id.ToString());
winInfo += string.Format("\tWorkset Id: {0}\n\n", win.WorksetId);
using (StreamWriter sw = new StreamWriter(@"c:\temp\WinIdInfo.txt", true))
{
sw.Write(winInfo);
}
MessageBox.Show(winInfo);
If the above code is put into the Excute() callback of an external command implementation and is either triggered directly from the Addin menu or a ribbon button associated with the command, some messages will be both written into a text file with nice format and displayed in a message box.
We can pick two windows in one Revit model and two others in another model, for example, and the output in the text file may look like the following.
Window Identification:
Element Id: 3133
Unique Id: 44f24687-579a-4d3b-9281-49b8c80c2593-00000c3d
Assembly Instance Id: -1
Type name: FamilyInstance
Type full name: Autodesk.Revit.DB.FamilyInstance
Category name: Windows
Category Id: -2000014
Symbol name: 24" x 72"
Symbol Id: 3097
ObjectType name: 24" x 72"
ObjectType Id: 3097
Host name: Wall 1
Host Id: 1912
Group name: N/A
Group Id: N/A
Space name: N/A
Space Id: N/A
Workset Id: 0
Window Identification:
Element Id: 3118
Unique Id: 44f24687-579a-4d3b-9281-49b8c80c2593-00000c2e
Assembly Instance Id: -1
Type name: FamilyInstance
Type full name: Autodesk.Revit.DB.FamilyInstance
Category name: Windows
Category Id: -2000014
Symbol name: 24" x 72"
Symbol Id: 3097
ObjectType name: 24" x 72"
ObjectType Id: 3097
Host name: Wall 1
Host Id: 1912
Group name: N/A
Group Id: N/A
Space name: N/A
Space Id: N/A
Workset Id: 0
Window Identification:
Element Id: 3133
Unique Id: 44f24687-579a-4d3b-9281-49b8c80c2593-00000c3d
Assembly Instance Id: -1
Type name: FamilyInstance
Type full name: Autodesk.Revit.DB.FamilyInstance
Category name: Windows
Category Id: -2000014
Symbol name: 24" x 72"
Symbol Id: 3097
ObjectType name: 24" x 72"
ObjectType Id: 3097
Host name: Wall 1
Host Id: 1912
Group name: N/A
Group Id: N/A
Space name: N/A
Space Id: N/A
Workset Id: 0
Window Identification:
Element Id: 3118
Unique Id: 44f24687-579a-4d3b-9281-49b8c80c2593-00000c2e
Assembly Instance Id: -1
Type name: FamilyInstance
Type full name: Autodesk.Revit.DB.FamilyInstance
Category name: Windows
Category Id: -2000014
Symbol name: 24" x 72"
Symbol Id: 3097
ObjectType name: 24" x 72"
ObjectType Id: 3097
Host name: Wall 1
Host Id: 1912
Group name: N/A
Group Id: N/A
Space name: N/A
Space Id: N/A
Workset Id: 0
The Element Id seems too obvious to mention. In fact, some readers may have noticed something out of expectations. Different models can have duplicate Element Ids. It can be reliably assumed though that each Element should have a unique ID in a single Revit model that has been loaded into a particular Revit session.
The Unique Id is some more interesting. Through parsing and calculations, we can figure that the last section of the so long a string is the hexadecimal representation of the ElementId integer value actually! Then can we expect that other sections/digits change with documents, work sets, or even computers?
Not likely! In this case, as mentioned, the first two windows came from a Revit model and the last two came from a different one, but they share all the same other sections in their Unique Ids as can be seen. So the long unique ids are not really unique, though other sections other than the element id hexadecimal representation part do look like some components of a GUID.
The type name and type full name are true obvious; they are the API class names here, FamilyInstance and Autodesk.Revit.DB.FamilyInstance. In fact, they are pure .NET things.
The Category name and ID are good to use to identify what the family instance (FamilyInstance) really is though still differences between them. The Category name looks culture/language dependant and the Category ID should not. Another reliable way is to compare the Category singleton instead as demonstrated many times before.
Now comes to the Symbol name and ID. They represent the family library/symbol that has been loaded into the Revit session and concreted into the family instances (windows) as we can see. Though different family symbols can all belong to a single category such as ‘Windows’ here, they have different sizes, graphics and parameters, so a different name/ID.
ObjectType is the obsolete API counterpart for the new API concept, Symbol.
Host name and ID indicate what element the windows are hosted by such as walls here. Group and Space indicate what Revit group and space that the windows may be defined in, which can be not applicable in most cases.
The Workset ID must have something to do with work sets and model sharing. 0 may mean the model is not in any work sets at all, which is the case here.
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