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.

How to copy element without click event?

Newbie
Participant

Below is sample code from AC Element Test, Is there anyone know could it possible to copy an element without click event by looping thru all select element's guid instead?

=================

void Do_CopyElem (void)
{
API_Element element = {};
API_ElementMemo memo = {};
GSErrCode err;

API_ElemType type;
API_Guid guid;
if (!ClickAnElem ("Click an element", API_ZombieElemID, nullptr, &type, &guid)) {
WriteReport_Alert ("No element was clicked");
return;
}

element.header.type = type;
element.header.guid = guid;

err = ACAPI_Element_Get (&element);
if (err == NoError)
err = ACAPI_Element_GetMemo (element.header.guid, &memo);
if (err != NoError) {
ErrorBeep ("ACAPI_Element_Get/Memo", err);
return;
}

if (err == NoError) {
element.header.floorInd ++;
err = ACAPI_Element_Create (&element, &memo);
if (err != NoError)
ErrorBeep ("ACAPI_Element_Create", err);
}

// ---- consistency check
if (err == NoError)
CompareElems (element, memo);
// ----

ACAPI_DisposeElemMemoHdls (&memo);
}
=================
1 REPLY 1

Hi,

Yes you should take a look at ACAPI_ElementList_GetList for that. Use API_ZombieElemID if you want to get elements of all types. Something like this:

 

GS::Array<API_Guid> allElements;
ACAPI_Element_GetElemList (API_ZombieElemID, &allElements);
for (auto elemGuid : allElements) {
    // Do your stuff here
}

 


Hope that helps!
Bernd