Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Revit element id from IFC encoded guid (22 characters)

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
peter.kolbe
2402 Views, 2 Replies

Get Revit element id from IFC encoded guid (22 characters)

peter.kolbe
Enthusiast
Enthusiast

I want to select a Revit element from a given IFC guid.

The following code is working as expected. But is there a more efficient way to find the Element Id?

Document doc = uiDoc.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc).WhereElementIsNotElementType();
foreach (Element ele in collector)
{
    var ids = new List<ElementId>();
    Guid elemGuid = ExportUtils.GetExportId(ele.Document, ele.Id);
    String exportGuid = IfcGuid.ToIfcGuid(elemGuid);
    if (ifcGuid.Equals(exportGuid))
    {
        ids.Add(ele.Id);
        uiDoc.Selection.SetElementIds(ids);
        break;
    }
}
0 Likes

Get Revit element id from IFC encoded guid (22 characters)

I want to select a Revit element from a given IFC guid.

The following code is working as expected. But is there a more efficient way to find the Element Id?

Document doc = uiDoc.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc).WhereElementIsNotElementType();
foreach (Element ele in collector)
{
    var ids = new List<ElementId>();
    Guid elemGuid = ExportUtils.GetExportId(ele.Document, ele.Id);
    String exportGuid = IfcGuid.ToIfcGuid(elemGuid);
    if (ifcGuid.Equals(exportGuid))
    {
        ids.Add(ele.Id);
        uiDoc.Selection.SetElementIds(ids);
        break;
    }
}
Tags (3)
2 REPLIES 2
Message 2 of 3
jeremytammik
in reply to: peter.kolbe

jeremytammik
Autodesk
Autodesk
Accepted solution

It depends on your situation.

 

If you know you will have this requirement ahead of time, for instance at the point of time when the IFC export takes place, you could create a dictionary mapping all export ids to the corresponding element ids and store that somewhere for future use. It could be inside the RVT model in extensible storage, or in a text file, database, or whatever.

 

The this operation would require one single super efficient dictionary lookup and nothing else.

 

I can imagine other approaches as well... depending on your situation and needs.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

It depends on your situation.

 

If you know you will have this requirement ahead of time, for instance at the point of time when the IFC export takes place, you could create a dictionary mapping all export ids to the corresponding element ids and store that somewhere for future use. It could be inside the RVT model in extensible storage, or in a text file, database, or whatever.

 

The this operation would require one single super efficient dictionary lookup and nothing else.

 

I can imagine other approaches as well... depending on your situation and needs.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3
peter.kolbe
in reply to: jeremytammik

peter.kolbe
Enthusiast
Enthusiast
Accepted solution

Thanks Jeremy,
I also think that a separate Dictionary<IFCguid, ElementId> is the solution.
I just wanted to make sure that there is no comparable API method for the same task.
Greetings Peter

0 Likes

Thanks Jeremy,
I also think that a separate Dictionary<IFCguid, ElementId> is the solution.
I just wanted to make sure that there is no comparable API method for the same task.
Greetings Peter

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report