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

[SOLVED] API_BuildingMaterialType->id crashes

ReignBough
Enthusiast
I am trying to access the ID of a building material through API_BuildingMaterialType.id. But the returned attribute got a null value for the id (also for manufacturer and description). (EDIT: And also on API_Attribute.header->uniStringNamePtr)
short cnt;
ACAPI_Attribute_GetNum(API_BuildingMaterialID, &cnt);
cnt++;
for (short i = 1; i < cnt; i++)
{
  API_Attribute attr;
  BNZeroMemory(&attr, sizeof(API_Attribute));
  attr.header.typeID = API_BuildingMaterialID;
  attr.header.index = i;
  err = ACAPI_Attribute_Get(&attr);
  if (err != NoError)
    continue;
  API_BuildingMaterialType bm = attr.buildingMaterial;
  if (!bm.id->IsEmpty())    // <----------- crashes when accessed
    //...
  //...
}
This is for both AC18 and AC19.
~ReignBough~
ARCHICAD 26 INT (from AC18)
Windows 11 Pro, AMD Ryzen 7, 3.20GHz, 32.0GB RAM, 64-bit OS
1 REPLY 1
ReignBough
Enthusiast
The solution for this is to pass a pointer to a valid GS::UniString variable in the ‘id’ field:
GS::UniString attrId;
ACAPI_Attribute attr;
 
BNZeroMemory (&attr, sizeof (attr));
attr.header.typeID = API_BuildingMaterialID;
attr.header.index = ….;
 
attr.buildingMaterial.id = &attrId;
if (ACAPI_Attribute_Get (&attr) == NoError)
{
  //... code here ...
}
This works similarly for ‘manufacturer’ and ‘description’.
~ReignBough~
ARCHICAD 26 INT (from AC18)
Windows 11 Pro, AMD Ryzen 7, 3.20GHz, 32.0GB RAM, 64-bit OS