Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

Looping through GS::Array<API_Guid>

dushyant
Booster
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 Alumni
Graphisoft Alumni
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
}

Konstantin
Newcomer
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
Booster
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
Advisor
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 10 - Visual Studio 2019; ArchiCAD 25

dushyant
Booster
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
Advisor
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 10 - Visual Studio 2019; ArchiCAD 25

dushyant
Booster
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!

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!