We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

question about getting an element's attribute

Anonymous
Not applicable
Hello Archicad developers!

I have a little trouble with getting the names of each element's composite. The issue is that each time I cycle through my elements it returns the first element's composite name. I suspect that I don't use the ACAPI_Element_Get function in the right way.

Here is part of my code:
 API_Element element;
    vector <elementsList> eL;
    GS::Array<API_ElemTypeID> typeIDs = {API_WallID, API_SlabID, API_RoofID}; // the types we are going to look for
 
    for(int i=0; i < typeIDs.GetSize(); i++){

        GS::Array<API_Guid> elemListGuid;
        ACAPI_Element_GetElemList (typeIDs, &elemListGuid); // get the elements for each type
        
        for(int k=0; k < elemListGuid.GetSize(); k++){
            WriteReport("element number %i", k);
            
           
            GSErrCode         err2;
            
            BNZeroMemory (&element, sizeof (API_Element));
            element.header.typeID = typeIDs;
            element.header.guid   = elemListGuid.Get(k); // GUID OF EACH ELEMENT
            
            err2 = ACAPI_Element_Get (&element); // GETTING THE ELEMENT ???
            
            if (err2 != NoError) {
                WriteReport_Alert ("Unknown element");
                return;
            }
            else{
                // we have element!
            }
            
            
            API_Attribute     attrib;
            GSErrCode         err3;
            
            BNZeroMemory (&attrib, sizeof (API_Attribute));
            
            attrib.header.typeID = API_CompWallID;
            attrib.header.index  = element.header.layer + 1; 
            
            err3 = ACAPI_Attribute_Get (&attrib);
            
            if (err3 == NoError){
               WriteReport_Alert("BINGO!! name is %s", attrib.header.name); // HERE IT ALWAYS PRINTS THE FIRST ELEMENT COMPOSITE NAME...
            }

        }
    }
1 REPLY 1
Anonymous
Not applicable
I have resolved this. The problem was that I was passing the element layer index, instead of the composite one. This was my solution:
 if(typeIDs == API_WallID){ // Its a wall
                compIndex = element.wall.composite;
            }
            
            if(typeIDs == API_SlabID){ // Its a slab
                compIndex = element.slab.composite;
            }
            
            if(typeIDs == API_RoofID){ // Its a roof
                compIndex = element.roof.shellBase.composite;
            }