We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

Getting a API_Guid from Library part

gehairing
Participant
Hello the Forum

What is the most clean method for getting an API_Guid from a Library part (API_LibPart) ?

I need to get & set IFC Data of a Library part.

Thanks.
5 REPLIES 5
gehairing
Participant
Hum...i answer to my own question
GS::UniString s = libpart.ownUnID;
GS::Guid gs_guid(s);
API_Guid ag  = GSGuid2APIGuid (gs_guid);
It seem's to work but i'm not sure it's the best method.
gehairing
Participant
Error : It doesn't work
gehairing
Participant
I have made a test function.

The functions gets the selected element in the model and get his API_Guid.
It also tries to get the GUID from the library part (if an library part is selected of course).

When I compare the Guid's...there are different.
Probably i am not understanding how all this works.

	// Scan all selected objects in AC
	API_SelectionInfo selectionInfo; 
	API_Neig **selNeigs;
	err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, false); 
	if (err == NoError) 
	{ 
		// If we have selected elements
		if (selectionInfo.typeID != API_SelEmpty) 
		{ 
			UInt32 ii, nSel; 
			nSel = BMGetHandleSize ((GSHandle) selNeigs) / sizeof (API_Neig); 
			for (ii = 0; ii < nSel && err == NoError; ii++) 
			{ 
				// Get selected element
				API_Element  element;
				BNZeroMemory (&element, sizeof (API_Element));
				element.header.guid  = (*selNeigs)[ii].guid;
				err = ACAPI_Element_Get(&element);
				if(err == NoError)
				{
					// Is it a library part
					API_LibPart libpart;
					BNZeroMemory (&libpart, sizeof (libpart));
					libpart.index = element.object.libInd;
					err = ACAPI_LibPart_Get (&libpart);
					if (err == NoError) 
					{
						// Yes it's a library part

						// Get elements guid
						API_Guid good_ag = element.header.guid;
							

						
// Get Guids from the library part and NOT from selected element
						GS::UniString s = libpart.ownUnID;
						GS::Guid gs_guid(s);
						API_Guid bad_ag  = GSGuid2APIGuid (gs_guid);

						GS::UniString s1 = libpart.parentUnID;
						GS::Guid gs_guid1(s1);
						API_Guid bad_ag1  = GSGuid2APIGuid (gs_guid1);

						DumpIFCProperties(libpart, good_ag);
Akos Somorjai
Graphisoft
Graphisoft
gehairing wrote:
I have made a test function.

The functions gets the selected element in the model and get his API_Guid.
It also tries to get the GUID from the library part (if an library part is selected of course).

When I compare the Guid's...there are different.
Probably i am not understanding how all this works.

	// Scan all selected objects in AC
	API_SelectionInfo selectionInfo; 
	API_Neig **selNeigs;
	err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, false); 
	if (err == NoError) 
	{ 
		// If we have selected elements
		if (selectionInfo.typeID != API_SelEmpty) 
		{ 
			UInt32 ii, nSel; 
			nSel = BMGetHandleSize ((GSHandle) selNeigs) / sizeof (API_Neig); 
			for (ii = 0; ii < nSel && err == NoError; ii++) 
			{ 
				// Get selected element
				API_Element  element;
				BNZeroMemory (&element, sizeof (API_Element));
				element.header.guid  = (*selNeigs)[ii].guid;
				err = ACAPI_Element_Get(&element);
				if(err == NoError)
				{
					// Is it a library part
					API_LibPart libpart;
					BNZeroMemory (&libpart, sizeof (libpart));
					libpart.index = element.object.libInd;
					err = ACAPI_LibPart_Get (&libpart);
					if (err == NoError) 
					{
						// Yes it's a library part

						// Get elements guid
						API_Guid good_ag = element.header.guid;
							

						
// Get Guids from the library part and NOT from selected element
						GS::UniString s = libpart.ownUnID;
						GS::Guid gs_guid(s);
						API_Guid bad_ag  = GSGuid2APIGuid (gs_guid);

						GS::UniString s1 = libpart.parentUnID;
						GS::Guid gs_guid1(s1);
						API_Guid bad_ag1  = GSGuid2APIGuid (gs_guid1);

						DumpIFCProperties(libpart, good_ag);
Hi,

The major difference between library parts and objects in the ARCHICAD API domain is that library parts refer to gsm files (in the embedded library, in an other lcf (library container file)), whereas the objects are placed instances of library parts.

I reckon you already have the GUID you need without going indirectly to the library part. The (*selNeigs)[ii].guid contains the GUID of the element (object) placed onto the floor plan; you should get the actual values of the IFC properties from there. After ACAPI_Element_Get please also check if the element.header.typeID is of any of the libpart-based elements (API_ObjectID, API_LampID), otherwise the element.object.libInd doesn't contain valid information.

Best, Ákos
gehairing
Participant
Thank you for the clarification