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] IFC name

Anonymous
Not applicable
Is it possible to get IFC name from element guid?
5 REPLIES 5
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Sure, you can get all IFC attributes and properties too!

Here is sample code for getting IFC name from element guid:
bool GetIFCNameFromElementGuid (const API_Guid& element_guid, GS::UniString* ifcName)
{
	GS::Array<API_IFCAttribute>  attributes;

	ACAPI_Element_GetIFCAttributes (element_guid, &attributes);
	for (GS::Array<API_IFCAttribute>::ConstIterator it = attributes.Enumerate (); it != NULL; ++it) {
		if ((*it).attributeName == "Name") {
			*ifcName = (*it).attributeValue;
			return true;
		}
	}

	return false;
}

// Usage:
GS::UniString ifcName;
GetIFCNameFromElementGuid (element_guid, &ifcName);
Anonymous
Not applicable
How can it convert GS::UniString to string or char ?
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
New wrote:
How can it convert GS::UniString to string or char ?


You can use ToCStr function like this:
GS::UniString gsUniString ("string_inside"); 
 
char* cString = gsUniString.ToCStr ().Get (); 
 
std::string str (gsUniString.ToCStr ());	// std::string str (gsUniString.ToCStr (0, GS::MaxUSize, CC_UTF8));
Anonymous
Not applicable
char* cString = gsUniString.ToCStr ().Get (); 

It didn't work like this, maybe i did something wrong, error: that const char* cannot be used to char*
Managed to work like this :
 char cString[32]; 
for (int ii=0;ii<32;ii++){ 
cString[ii] = *gsUniString.ToCStr (ii).Get ();  
}

---------------------------------------------------------------------------------------
std::string str (gsUniString.ToCStr ());  

This way everything worked fine will use function this way.

Again, thanks Tibor .
Anonymous
Not applicable
char* cString = gsUniString.ToCStr ().Get ();
Found better solution simple just:
 const char* cString = gsUniString.ToCStr().Get();
And everythings works fine
Learn and get certified!