BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

Archicad C++ API
About Archicad add-on development using the C++ API.

[SOLVED] How to find element by IFC Guid

Anonymous
Not applicable
Hi

My goal is to find element by IFC Guid
I have no choice to find by TagID because I'm getting IfcGUID from webAPI and I have to search by IFC GUID.

Is there any way to do that ?

Thanks in advance!


ifcguid.png

2 REPLIES 2
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

First you have to convert string IFC guid to API_Guid, after that you can search the elements with the given guid.
Here is an example code for you:
GS::UniString	ifcGuid = "32vZ_y6Kf8bQUeOicmrSnx"; // string IFC Guid 
API_Guid		apiGuid; 
if (ACAPI_Goodies (APIAny_IFCGuidToAPIGuidID, &ifcGuid, &apiGuid, NULL) == NoError) { 
	GS::Array<API_Guid> elements; 
 
	if (ACAPI_Element_GetElemListByIFCIdentifier (NULL, &apiGuid, elements) == NoError) { 
		for (GS::Array<API_Guid>::ConstIterator it = elements.Enumerate (); it != NULL; ++it) { 
			API_Element	element; 
			BNZeroMemory (&element, sizeof (API_Element)); 
			element.header.guid = *it; 
 
			if (ACAPI_Element_Get (&element) == NoError) { 
				// now you have the element 
			} 
		} 
	} 
}


Regards,
Tibor
Anonymous
Not applicable
Thank you very much for the help Tibor.

But I changed a thing in your code in order elements comes not empty

I also pass &apiGuid as first parameter of ACAPI_Element_GetElemListByIFCIdentifier

like this

ACAPI_Element_GetElemListByIFCIdentifier (&apiGuid, &apiGuid, elements)

Thanks
Learn and get certified!