cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
2024 Technology Preview Program

2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations

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

Creating a Zone Element

Anonymous
Not applicable
Hi,

Is it possible to create a Zone Element through the API? I've tried to create an Element with type API_ZoneID but nothing happens. From what I understand, I would need to create a Polygon for creating the zone, but I can't find any information or example on that. Here's my code:

API_Coord clickedPoint;
if (!ClickAPoint("Origem", &clickedPoint)) {
    return;
}
ACAPI_OpenUndoableSession("Do it!");

API_Element zoneElement;
API_ElementMemo zoneElementMemo;
BNZeroMemory(&zoneElement, sizeof(API_Element));	
BNZeroMemory(&zoneElementMemo, sizeof(API_ElementMemo));

zoneElement.header.typeID = API_ZoneID;
ACAPI_Element_GetDefaults(&zoneElement, &zoneElementMemo);

zoneElement.zone.manual = true;
// Code to create Polygon???

ACAPI_Element_Create(&zoneElement, &zoneElementMemo);
ACAPI_CloseUndoableSession();
Is that even possible? Any help would be appreciated!
2 REPLIES 2
Akos Somorjai
Graphisoft
Graphisoft
Andre wrote:
Hi,

Is it possible to create a Zone Element through the API? I've tried to create an Element with type API_ZoneID but nothing happens. From what I understand, I would need to create a Polygon for creating the zone, but I can't find any information or example on that. Here's my code:

API_Coord clickedPoint;
if (!ClickAPoint("Origem", &clickedPoint)) {
    return;
}
ACAPI_OpenUndoableSession("Do it!");

API_Element zoneElement;
API_ElementMemo zoneElementMemo;
BNZeroMemory(&zoneElement, sizeof(API_Element));	
BNZeroMemory(&zoneElementMemo, sizeof(API_ElementMemo));

zoneElement.header.typeID = API_ZoneID;
ACAPI_Element_GetDefaults(&zoneElement, &zoneElementMemo);

zoneElement.zone.manual = true;
// Code to create Polygon???

ACAPI_Element_Create(&zoneElement, &zoneElementMemo);
ACAPI_CloseUndoableSession();
Is that even possible? Any help would be appreciated!
Hello Andre,

Yes, absolutely!

Two places you can look at, both are in the Element_Basics.cpp source file in the Element_Test example:
  • -> Do_CreateSlab shows you how you can assemble the appropriate polygon
    -> Do_CreateAutoZone demonstrates how you can do it without supplying a polygon
Best, Akos
Anonymous
Not applicable
It worked, thanks a lot!

For future reference, here's the code I've used:

ACAPI_OpenUndoableSession("Do It!");

API_Element zoneElement;
API_ElementMemo elementMemo;
BNZeroMemory(&zoneElement, sizeof(API_Element));	
BNZeroMemory(&elementMemo, sizeof(API_ElementMemo));

zoneElement.header.typeID = API_ZoneID;
zoneElement.header.layer = CriarLayer();
ACAPI_Element_GetDefaults(&zoneElement, &elementMemo);

zoneElement.zone.manual = true;
zoneElement.zone.pos.x = clickedPoint.x;
zoneElement.zone.pos.y = clickedPoint.x;
zoneElement.zone.refPos.x = clickedPoint.x;
zoneElement.zone.refPos.y = clickedPoint.x;

zoneElement.zone.poly.nCoords = 5;
zoneElement.zone.poly.nSubPolys = 1;
zoneElement.zone.poly.nArcs = 0;

elementMemo.coords = (API_Coord**) BMAllocateHandle ((zoneElement.zone.poly.nCoords + 1) * sizeof (API_Coord), ALLOCATE_CLEAR, 0);
elementMemo.pends  = (Int32**) BMAllocateHandle ((zoneElement.zone.poly.nSubPolys + 1) * sizeof (Int32), ALLOCATE_CLEAR, 0);
if (elementMemo.coords != NULL && elementMemo.pends != NULL) {
	(*elementMemo.coords)[1].x = clickedPoint.x - 1.0;
	(*elementMemo.coords)[1].y = clickedPoint.y;
	(*elementMemo.coords)[2].x = clickedPoint.x;
	(*elementMemo.coords)[2].y = clickedPoint.y - 1.0;
	(*elementMemo.coords)[3].x = clickedPoint.x + 1.0;
	(*elementMemo.coords)[3].y = clickedPoint.y;
	(*elementMemo.coords)[4].x = clickedPoint.x;
	(*elementMemo.coords)[4].y = clickedPoint.y + 1.0;
	(*elementMemo.coords)[5].x = (*elementMemo.coords)[1].x;
	(*elementMemo.coords)[5].y = (*elementMemo.coords)[1].y;

	(*elementMemo.pends)[0] = 0;
	(*elementMemo.pends)[1] = zoneElement.zone.poly.nCoords;
}

GSErrCode err = ACAPI_Element_Create(&zoneElement, &elementMemo);
if (err != NoError)
	ErrorBeep ("ACAPI_Element_Create (Zone)", err);
ACAPI_DisposeElemMemoHdls (&elementMemo);
ACAPI_CloseUndoableSession();