BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

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

[SOLVED] Guid array

Anonymous
Not applicable
for (GS::Array<API_Guid>::ConstIterator it = elements.Enumerate (); it != NULL; ++it) {   
         BNZeroMemory (&element, sizeof (API_Element));   
         element.header.guid = *it; 


I have specified witch guid to get. And i need to store them in array. I guess i'm doing something wrong.
When i use like this, Archicad crashes.:
API_Guid *arrayGuid  
arrayGuid=*it;
1 REPLY 1
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
First you must allocate the memory for the array. There are several ways to do that, here is one for example:
// allocate memory for the array:
API_Guid** arrayGuid = (API_Guid**) BMAllocateHandle (elements.GetSize () * sizeof (API_Guid), ALLOCATE_CLEAR, 0);

// using the array:
(*arrayGuid) = (*it);

// when finished the work with the array don't forget to free the memory:
BMKillHandle ((GSHandle *) &arrayGuid);
Or if you don't want to bother with memory handling, then you should use GS::Array for this purpose:
GS::Array<API_Guid> arrayGuid;
arrayGuid.Push (*it);
// or insert it to a specific index:
arrayGuid.Insert (i, *it);

// you can get the pointer to the array content also:
API_Guid* arrayGuidPointer = arrayGuid.GetContent ();
arrayGuidPointer = (*it);
Learn and get certified!