License Delivery maintenance is expected to occur on Saturday, November 30, between 8 AM and 11 AM CET. This may cause a short 3-hours outage in which license-related tasks: license key upload, download, update, SSA validation, access to the license pool and Graphisoft ID authentication may not function properly. We apologize for any inconvenience.
Archicad C++ API
About Archicad add-on development using the C++ API.

APIERR_BADINDEX getting element

Anonymous
Not applicable
Hello,

I've found on several drawings in ArchiCAD 9 an ACAPI_Element_Get returns APIERR_BADINDEX. Just wondering how this could happen? It doesn't happen in ArchiCAD 7.

Here is what my code is doing:

ACAPI_Element_GetNum(API_TextID, &num);
for(ii=1;ii<=num;++ii)
{
   if(ACAPI_Element_Filter(API_TextID, ii, APIFilt_IsEditable))
   {
      memset(&element, 0, sizeof(API_Element));
      element.header.index = ii;
      element.header.typeID = API_TextID;
      err = ACAPI_Element_Get(&element);
      if(err == APIERR_BADINDEX)
      {
            // this is true when ii==num which should be a valid index, shouldn't it ?
      }
}

2 REPLIES 2
Ralph Wessel
Mentor
adambutler wrote:
I've found on several drawings in ArchiCAD 9 an ACAPI_Element_Get returns APIERR_BADINDEX. Just wondering how this could happen? It doesn't happen in ArchiCAD 7.
The number returned by ACAPI_Element_Get is the highest index used in the database, which is not necessarily the number of elements in the database. The documentation states:
Please note that the returned number does not necessarily match the number of existing elements of that type, as the ArchiCAD database may contain deleted elements as well; see the ACAPI_Element_Filter function for more details.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Hello,

My concern is that I am filtering the elements, so this element with a bad index is not deleted. I think I will have to go through my code and 'continue' if I get a badindex result from an ACAPI_Element_Get

Thanks,
Adam