License delivery maintenance is planned for Saturday, July 26, between 12:00 and 20:00 CEST. During this time, you may experience outages or limited availability across our services, including BIMcloud SaaS, License Delivery, Graphisoft ID (for customer and company management), Graphisoft Store, and BIMx Web Viewer. More details…

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

Looping through GS::Array<API_Guid>

dushyant
Enthusiast
Hi

How can I loop through the items stored in a GS::Array<API_Guid> array? I want to print all the Guids stored in it, say via ACAPI_WriteReport()..
(Also, how do you normally print out data to check values while developing/debugging?)

I tried: for (int i = 0; i < sizeof(arrayName); i++) { .. } but it is giving out some strange results.

Thanks
7 REPLIES 7
Viktor Kovacs
Graphisoft
Graphisoft
You can use it like an std::vector.

For example:

for (UIndex i = 0; i < array.GetSize (); i++) {
    const API_Guid& guid = array;
    // do something with the guid
}
or

for (const API_Guid& guid : array) {
    // do something with the guid
}
Anonymous
Not applicable
Hi, try:

GS::Array<API_Guid> array;
    for(auto element : elemList)
    {...}
or

    for (GS::Array<API_Guid>::ConstIterator element = array.Enumerate(); element  != nullptr; ++element )
    {...}
dushyant
Enthusiast
Thanks Viktor and Konstantin.

I am trying to print the Guids using ACAPI_WriteReport() , as I don't know of any other way to print debug info in Archicad, using the "%s" format specifier, like this:
for (const API_Guid& guid : arrayOfGuids) {
      ACAPI_WriteReport("%s", false, guid);
}
It is not printing anything. How to print an API_Guid ?

Thanks
poco2013
Mentor
This will work but is not the optimum way. Someone else may input the proper utility but this is what I use.

char hold[254] = {};
APIGuid2GSGuid(guid).ConvertToString(hold)
ACAPI_WriteReport("%s",false,hold);
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
dushyant
Enthusiast
poco2013 wrote:
This will work but is not the optimum way. Someone else may input the proper utility but this is what I use.
Code: Select all

char hold[254] = {};
APIGuid2GSGuid(guid).ConvertToString(hold)
ACAPI_WriteReport("%s",false,hold);
Thanks Gerry, that worked perfectly.

So API-Guid and GS-Guid are different?
poco2013
Mentor
dushyant wrote:

So API-Guid and GS-Guid are different?
They are essentially the same thing except GS::Guid is packed as a Class and API_Guid is a structure.

From the API Manual:
"API_Guid is essentially a GS::Guid. It has the same size and structure, and only exists because of certain C++ language limitations: namely that a union (like API_Element) cannot contain a class which has a constructor or destructor. Since API_Elem_Head needs to contain a Guid member, and it cannot be a GS::Guid, the API_Guid structure was introduced."
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
dushyant
Enthusiast
poco2013 wrote:
They are essentially the same thing except GS::Guid is packed as a Class and API_Guid is a structure.

From the API Manual:

"API_Guid is essentially a GS::Guid. It has the same size and structure, and only exists because of certain C++ language limitations: namely that a union (like API_Element) cannot contain a class which has a constructor or destructor. Since API_Elem_Head needs to contain a Guid member, and it cannot be a GS::Guid, the API_Guid structure was introduced."
Thanks a lot Gerry!