Getting GUID of Elements in RevitLinkInstance

Getting GUID of Elements in RevitLinkInstance

lvirone
Enthusiast Enthusiast
1,752 Views
7 Replies
Message 1 of 8

Getting GUID of Elements in RevitLinkInstance

lvirone
Enthusiast
Enthusiast

Hi everyone,

 

I'm trying to retrieve the GUIDs of elements within a RevitLinkInstance to generate reports that can accurately identify elements across a Document and an IFC file.

 

For a better understanding of GUIDs in Revit, you can refer to this helpful resource: https://thebuildingcoder.typepad.com/blog/2009/02/uniqueid-dwf-and-ifc-guid.html

 

The problem : The methods I know for obtaining a GUID, but neither provides the GUID of an element in a RevitLinkInstance. Instead, they always return the GUID as if the linked document is the active one.

 

Important Note: I cannot use the "IFC GUID" parameter because it is not populated for elements within a link.

 

Exemple : I have a Document containing two identical RevitLinkInstance objects (from the same RevitLinkType). When exporting an IFC, the same element from the RevitLinkType gets different GUIDs depending on which RevitLinkInstance owns it.

 

Even if I set the linked document as the active one and export an IFC, the resulting GUIDs are still different. Fortunately, these GUIDs from the Active Document can be obtained using specific API methods or algorithms (detailed below).

 

Exsting API method and algorithm :

  1. "ExportUtils.GetExportId"
  2. "ExporterIFCUtils.CreateAlternateGUID"

 

Request for Assistance

Does anyone know a method or workaround to get the GUID of an element within a RevitLinkInstance instead of the linked document itself?

 

Thanks in advance for your help!

0 Likes
Accepted solutions (1)
1,753 Views
7 Replies
Replies (7)
Message 2 of 8

Moustafa_K
Advisor
Advisor

I'm not sure if the case I faced is exactly like yours, but I also struggled to get a unique ID or GUID for an element to track it seamlessly between IFC and Revit. While exploring the IFC Exporter open-source code, I gained insights into how these identifiers are managed internally.

 

I wrote an article that provides a detailed roadmap for extracting unique IDs from a RevitLinkInstance. It might help you achieve what you're looking for. Here's a glimpse of the approach, including a code snippet:

 

public string GenerateIFCGuidFrom(Element e, RevitLinkInstance rvtInstance)
{
    if (e == null)
        throw new ArgumentException("Missing element");

    // Get the IFC GUID of the element
    var eIfc = e.get_Parameter(BuiltInParameter.IFC_GUID).AsString();
    if (rvtInstance == null)
        return eIfc;

    // Get the IFC GUID of the RevitLinkInstance
    var rvtInsIfc = rvtInstance.get_Parameter(BuiltInParameter.IFC_GUID).AsString();

    // Combine the GUIDs to generate a unique identifier
    string expectedIFc = GenerateIFCGuidFrom(eIfc, rvtInsIfc);
    expectedIFc = GenerateIFCGuidFrom(expectedIFc, rvtInsIfc);

    return expectedIFc;
}

 

 

For the full explanation and additional insights, check out the article:
Mapping IFC GUIDs Between Revit and Exported Files.

It covers the logic behind this method and other useful techniques for working with GUIDs in Revit.

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 3 of 8

lvirone
Enthusiast
Enthusiast

Hello @Moustafa_K 

 

Thank you for the answer ! I found the exact method from the IFC exporter here : https://github.com/Autodesk/revit-ifc/blob/master/Source/Revit.IFC.Export/Utility/GUIDUtil.cs

 

BUT when I use your code or the code from the exporter the IFC GUID of elements in a RevitLinkInstance are still not the same. Did you test it with real case ?

 

True case :

An Element with parameter IFC_GUID = "1HuGrbDRvAgh8g1RIAPZTa" in a RevitLinkInstance with IFC_GUID = "3$OKAVYWHA2Bf_9Q8fLkdg", the method return "0wJLUMVTv5VV20lWXsUqyq" but in the IFC file the GUID value is "0OaMFIbq4IKPjrztQLfsE7". When I export to IFC I selected "Export links in same IfcBuilding".

 

Thanks again

0 Likes
Message 4 of 8

Moustafa_K
Advisor
Advisor

Yep I have tested but it would be interesting to see exceptions that i have to consider. Can you send me this revit sample...

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 5 of 8

lvirone
Enthusiast
Enthusiast

I created a new project 2024.1 "Projet3" with the file "Link" as a link. The IFC "Projet 3 " is generated from the file with the same name and I selected "Export links in same IfcBuilding".

 

In this sample, I tested the values for a Wall :

//Expected : 2gT592YIAEkpJYnF6cz9Uv
//Generated : 1mto5M_afA48XA9UefAkjZ
GenerateIFCGuidFrom("1WpMewUK1BxuEFpwtJZGNn", "3iM8cpmJLFvvMkQx2D$mpR");

0 Likes
Message 6 of 8

Moustafa_K
Advisor
Advisor
Accepted solution

It works fine on my end:
[1] ElementId: 150778 ==> IFCParameter: 1WpMewUK1BxuEFpwtJZGNg ==> IFCGuid: 1xQ$iFqXHRRvDVpMIQRRrf

[2] ElementId: 150753 ==> IFCParameter: 1WpMewUK1BxuEFpwtJZGNn ==> IFCGuid: 2gT592YIAEkpJYnF6cz9Uv

 

Possibly there is a missing implementation on your code

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 7 of 8

lvirone
Enthusiast
Enthusiast

Yes, I didn't notice that you were calling the method twice, once with the value already calculated.

string expectedIFc = GenerateIFCGuidFrom(eIfc, rvtInsIfc);
expectedIFc = GenerateIFCGuidFrom(expectedIFc, rvtInsIfc);

 

Sorry for the inconvenience, and thank you very much!

0 Likes
Message 8 of 8

Moustafa_K
Advisor
Advisor

Glad it works for you, and thanks for confirming.

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1