Looping through GS::Array<API_Guid>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-08-20
01:09 PM
- last edited on
2021-09-14
09:20 AM
by
Noemi Balogh
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
- Labels:
-
Add-On (C++)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-08-20 02:57 PM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-08-20 02:58 PM
GS::Array<API_Guid> array;
for(auto element : elemList)
{...}
or
for (GS::Array<API_Guid>::ConstIterator element = array.Enumerate(); element != nullptr; ++element )
{...}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-08-20 03:30 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-08-21 12:18 AM
char hold[254] = {};
APIGuid2GSGuid(guid).ConvertToString(hold)
ACAPI_WriteReport("%s",false,hold);
Windows 11 - Visual Studio 2022; ArchiCAD 27
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-08-21 11:04 AM
poco2013 wrote:Thanks Gerry, that worked perfectly.
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);
So API-Guid and GS-Guid are different?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-08-21 11:27 AM
dushyant wrote:They are essentially the same thing except GS::Guid is packed as a Class and API_Guid is a structure.
So API-Guid and GS-Guid are different?
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."
Windows 11 - Visual Studio 2022; ArchiCAD 27
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-08-23 08:15 AM
poco2013 wrote:Thanks a lot Gerry!
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."