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

GSModeler element to API_element

Anonymous
Not applicable
Hi All,

I have the GSModeler elements of a model, and I would like to get parameters from it. (material, volume, etc..). Could you please share a piece of code how can I get this through the API?

Thanks: Andor
4 REPLIES 4
Anonymous
Not applicable
This is the place I am stuck at. Overall am I heading to the right direction to get the wanted properties of the elements?
API_Element      apiElement;
	API_ElementMemo  memo;
	GSErrCode        err;
	//const API_Guid		 APIGuid;
	BNZeroMemory (&element, sizeof (API_Element));
	const GS::Guid GSGuid = element.GetElemGuid();
	//&APIGuid =  GSGuid2APIGuid ( &GSGuid);
	err = ACAPI_Element_GetMemo(const API_Guid&    GSGuid2APIGuid(&GSGuid), &memo);
	if (err == NoError) {
		
	}
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Szia Andor,

here is a short example code to get the volume and surface areas of an element:
GSErrCode PrintElementSurfaceAndVolume (const API_Guid& guid) 
{ 
	API_Quantity      quantity, mask; 
	API_Quantities    quantities; 
	API_QuantityPar   params; 
	char              s[256] = { '\0' }; 
	GSErrCode         err; 
 
	ACAPI_ELEMENT_QUANTITY_MASK_CLEAR (mask); 
	ACAPI_ELEMENT_QUANTITY_MASK_SET (mask, wall, surface1); 
	ACAPI_ELEMENT_QUANTITY_MASK_SET (mask, wall, surface2); 
	ACAPI_ELEMENT_QUANTITY_MASK_SET (mask, wall, volume); 
	// Check API_Quantity and API_WallQuantity in the documentation for other options to set! 
 
	quantities.quantityData = &quantity; 
	params.minOpeningSize = EPS; 
	err = ACAPI_Element_GetQuantities (guid, &params, &quantities, &mask); 
	if (err == NoError) { 
	    sprintf (s, "surface1: %.2lf  surface2: %.2lf  volume: %.2lf", quantity.wall.surface1, quantity.wall.surface2, quantity.wall.volume); 
	    ACAPI_WriteReport (s, true); 
	} 
	return err; 
}

// how to use this function:

ModelerAPI::Element element;
	//...
	//...
PrintElementSurfaceAndVolume (GSGuid2APIGuid (element.GetElemGuid ()));

Soon I will write an example for getting materials too.

Best Regards,
Tibor
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Szia Andor,

to get the material informations of a GModeler element you should iterate through the polygons of the element.
// first you should get the model  
	ModelerAPI::Model model;  
  
// then you can iterate through the elements, bodies and polygons of the model  
	Int32						iElement = 0, iBody = 0, iPgon = 0;  
	Int32						nBody = 0, nPoly = 0;  
	Int32						nElements = model->GetElementNum ();  
	ModelerAPI::Element			element;  
	ModelerAPI::Body				body;  
	ModelerAPI::Polygon			polygon;
  
	for (iElement = 1; iElement <= nElements; iElement++) {  
		model->GetElement (iElement, &element);  
		nBody = element.GetBodyNum ();  
  
		for (iBody = 1; iBody <= nBody; iBody++) {  
			element.GetBody (iBody, &body);  
			nPoly = body.GetPolygonCount ();  
  
			for (iPgon = 1; iPgon <= nPoly; iPgon++) {  
				body.GetPolygon (iPgon, &polygon);  
  
				// now you can get the material of this polygon  
				ModelerAPI::Material material;  
				model->GetMaterial (polygon.GetMaterialIndex (), &material);  
				ModelerAPI::Color color = material.GetSurfaceColor ();  
				double alpha = material.GetTransparency ();  
				// check other available informations about the material in GSModelDevLib/ModelMaterial.hpp  
			}  
		}  
	}


Hope this helps!

Best Regards,
Tibor
Anonymous
Not applicable
Szia Tibor!

Thanks a lot