cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Archicad C++ API
About Archicad add-on development using the C++ API.

How can I apply override surfaces?

VladicaZivic
Newcomer

For now,  in my Archicad addon, I need to apply override surfaces for these ("Outside Face Surface", "Internal Face Surface" & "Edge Surface") to be linked together with AC API. (they should be same material)

So I have tried to use this code, but I am always get "GSErrCode" of "-2130312307". 
ChatGPT said it's read-only access issue, so I have tried the code after saving the project file. 
I am already purchased license so there should be no such problem.

Here is my code.

 

void ApplySameOverrideSurface()
{
GS::Array<API_Guid> elemList;
GSErrCode err = ACAPI_Element_GetElemList(API_ZombieElemID, &elemList, APIFilt_OnVisLayer);
if (err != NoError)
return;

for (const API_Guid& guid : elemList) {
API_Element element;
BNZeroMemory(&element, sizeof(API_Element));
element.header.guid = guid;

if (ACAPI_Element_Get(&element) != NoError)
continue;

int type;
#if AC_VERSION >= 26
type = element.header.type.typeID;
#else
type = element.header.typeID;
#endif

API_AttributeIndex index;
index = CreateAttributeIndex(1);

API_Element mask;
ACAPI_ELEMENT_MASK_CLEAR(mask);

bool pass = type == API_WallID || API_ObjectID;

if (pass == false)
continue;

switch (type)
{
case API_WallID:
//element.wall.composite != CreateAttributeIndex(0) ? index = element.wall.composite : index = element.wall.buildingMaterial;
element.wall.oppMat = element.wall.buildingMaterial;
element.wall.refMat = element.wall.buildingMaterial;
element.wall.sidMat = element.wall.buildingMaterial;

ACAPI_ELEMENT_MASK_SET(mask, API_WallType, oppMat);
ACAPI_ELEMENT_MASK_SET(mask, API_WallType, refMat);
ACAPI_ELEMENT_MASK_SET(mask, API_WallType, sidMat);
break;
case API_ObjectID:
element.object.mat = index;
element.object.useObjMaterials = false;
ACAPI_ELEMENT_MASK_SET(mask, API_ObjectType, mat);
ACAPI_ELEMENT_MASK_SET(mask, API_ObjectType, useObjMaterials);
break;
}

//// Now apply changes
err = ACAPI_Element_Change(&element, &mask, nullptr, 0, true);
if (err != NoError) {
DBPrintf("Failed to override surface for element: %s\n", APIGuidToString(guid).ToCStr().Get());
}
}
}


If anyone knows the reason, please let me know about it asap. 

Kind Regards,
Vladica Zivic

 

Operating system used: Windows


image.png

 

image.png

5 REPLIES 5
VladicaZivic
Newcomer

Here are the screenshots.
Kind Regards,
Vladica


Screenshot_2.png

 

Screenshot_3.png

Oleg
Expert

Don't believe ChatGPT 😀

API ErrorCode:

 

APIERR_NEEDSUNDOSCOPE -2130312307 8106038D The called command should be encapsulated in a ACAPI_CallUndoableCommand scope.


You need to call the ACAPI_Element_Change in a ACAPI_CallUndoableCommand.
 

Oleg
Expert

Dont belive ChatGPT 😀

API ErrorCide:

APIERR_NEEDSUNDOSCOPE -2130312307 8106038D The called command should be encapsulated in a ACAPI_CallUndoableCommand scope.


Some functions like the ACAPI_Element_Change should be called in a ACAPI_CallUndoableCommand.

Oleg
Expert

I tried to reply twice, but the answers were not published. I'll try again.

 

Error -2130312307 is:

 

APIERR_NEEDSUNDOSCOPE "The called command should be encapsulated in a ACAPI_CallUndoableCommand scope"

Some functions should be called in a  ACAPI_CallUndoableCommand.
See documentation on ACAPI_CallUndoableCommand and examples.

@Oleg  FYI Auto Spam was hiding the message.

Eduardo Rolón AIA NCARB
AC28 US/INT -> AC08

Macbook Pro M1 Max 64GB ram, OS X 10.XX latest
another Moderator

Setup info provided by author