<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Retrieving Names and Bounding Boxes of Building Elements in ArchiCAD Add-On in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581123#M9017</link>
    <description>&lt;P&gt;For the bounding box you can use the&amp;nbsp;&lt;STRONG&gt;ACAPI_Element_CalcBounds&lt;/STRONG&gt; function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the name it depends on what you are trying to do. It may be different for some element types, but these are functions that work with all types:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;ACAPI_Element_GetElemTypeName&lt;/STRONG&gt; will return the localized name of the element type (like Wall, Slab, Zone, etc.)&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ACAPI_Element_GetElementInfoString&lt;/STRONG&gt; will return the user defined ID field of the element, and almost all elements have this field.&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Wed, 20 Dec 2023 05:52:44 GMT</pubDate>
    <dc:creator>Viktor Kovacs</dc:creator>
    <dc:date>2023-12-20T05:52:44Z</dc:date>
    <item>
      <title>Retrieving Names and Bounding Boxes of Building Elements in ArchiCAD Add-On</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581081#M9015</link>
      <description>&lt;P&gt;Hello ArchiCAD Developer Community,&lt;/P&gt;
&lt;P&gt;I'm currently developing an add-on for ArchiCAD and have encountered a challenge that I need some assistance with. My add-on aims to process various building elements like walls, slabs, and doors, and I need to retrieve not only their GUIDs but also their names (or local names) and bounding boxes.&lt;/P&gt;
&lt;P&gt;So far, I have successfully obtained the GUIDs of the elements, but I'm struggling with how to fetch their names and bounding boxes. I'm looking for a way to access these additional details for each building element.&lt;/P&gt;
&lt;P&gt;Here's a summary of my current approach:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The add-on iterates through building elements and retrieves their GUIDs.&lt;/LI&gt;
&lt;LI&gt;I'm using functions like ACAPI_Element_Get and ACAPI_Element_GetMemo to fetch element data.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;My question is:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;How can I retrieve the name or local name of each building element (e.g., "Wall 1", "Slab A", etc.)?&lt;/LI&gt;
&lt;LI&gt;Additionally, how can I obtain the bounding box of each element?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I suspect there are specific API functions or properties that I need to use, but I haven't been able to find the right approach.&lt;/P&gt;
&lt;P&gt;Here is a snippet of the code where I process the elements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void ReportElementProperties(const API_Guid&amp;amp; elementGuid, API_ElemTypeID elemType, std::ofstream&amp;amp; outFile)
{
    char reportStr[1024];
    API_Element element;
    BNZeroMemory(&amp;amp;element, sizeof(API_Element));
    element.header.guid = elementGuid;

    // Retrieve the element
    if (ACAPI_Element_Get(&amp;amp;element) == NoError) {
        GS::UniString elemName;
        // Handle Zone type specifically
        if (elemType == API_ZoneID) {
            // Assuming API_ZoneID correctly identifies a Zone
            API_ZoneType&amp;amp; zone = element.zone;
            GS::Guid gsGuid = APIGuid2GSGuid(zone.stampGuid);
            std::string guidStr = (const char*)gsGuid.ToUniString().ToCStr().Get();
            sprintf(reportStr, "Zone Stamp GUID: %s, Position: (%.2f, %.2f)", guidStr.c_str(), zone.pos.x, zone.pos.y);

            // Include the room or zone name if it exists
            if (!zone.roomName[0]) {
                strcat(reportStr, ", Room/Zone Name: ");
                strcat(reportStr, (const char*)zone.roomName);
            }
        }
        else if (elemType == API_DoorID) {
            // Handle Door elements

            API_DoorType&amp;amp; door = element.door;
            // Access markGuid from openingBase
            GS::Guid markGuid = APIGuid2GSGuid(door.openingBase.markGuid);
            std::string markGuidStr = (const char*)markGuid.ToUniString().ToCStr().Get();
            sprintf(reportStr, "Door Element, GUID: %s, Marker GUID: %s", APIGuidToString(elementGuid).ToCStr().Get(), markGuidStr.c_str());
        }

        else {
            // Handle other types (walls, slabs, etc.)
            if (ACAPI_Element_GetElemTypeName(elemType, elemName) == NoError) {
                sprintf(reportStr, "Element Type: %s, GUID: %s", (const char*)elemName.ToCStr(), APIGuidToString(elementGuid).ToCStr().Get());
            }
            else {
                sprintf(reportStr, "Element Type: %d, GUID: %s", elemType, APIGuidToString(elementGuid).ToCStr().Get());
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any guidance on how to retrieve both the name and bounding box for each building element within the add-on would be greatly appreciated. Are there specific API calls or structs that I should be looking into? &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance for your time and assistance!&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 12:41:18 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581081#M9015</guid>
      <dc:creator>sercet65</dc:creator>
      <dc:date>2024-09-16T12:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving Names and Bounding Boxes of Building Elements in ArchiCAD Add-On</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581123#M9017</link>
      <description>&lt;P&gt;For the bounding box you can use the&amp;nbsp;&lt;STRONG&gt;ACAPI_Element_CalcBounds&lt;/STRONG&gt; function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the name it depends on what you are trying to do. It may be different for some element types, but these are functions that work with all types:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;ACAPI_Element_GetElemTypeName&lt;/STRONG&gt; will return the localized name of the element type (like Wall, Slab, Zone, etc.)&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ACAPI_Element_GetElementInfoString&lt;/STRONG&gt; will return the user defined ID field of the element, and almost all elements have this field.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 20 Dec 2023 05:52:44 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581123#M9017</guid>
      <dc:creator>Viktor Kovacs</dc:creator>
      <dc:date>2023-12-20T05:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving Names and Bounding Boxes of Building Elements in ArchiCAD Add-On</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581270#M9028</link>
      <description>&lt;P&gt;&lt;a href="https://community.graphisoft.com/t5/user/viewprofilepage/user-id/12765"&gt;@Viktor Kovacs&lt;/a&gt;&amp;nbsp;Thank you very much for the feedback.&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// Retrieve the element
    if (ACAPI_Element_Get(&amp;amp;element) == NoError) {
        GS::UniString elemName;
        // Handle Zone type specifically
        if (elemType == API_ZoneID) {
            // Assuming API_ZoneID correctly identifies a Zone
            API_ZoneType&amp;amp; zone = element.zone;
            GS::Guid gsGuid = APIGuid2GSGuid(zone.stampGuid);
            std::string guidStr = (const char*)gsGuid.ToUniString().ToCStr().Get();
            sprintf(reportStr, "Zone Stamp GUID: %s, Position: (%.2f, %.2f)", guidStr.c_str(), zone.pos.x, zone.pos.y);

            // Include the room or zone name if it exists
            if (!zone.roomName[0]) {
                strcat(reportStr, ", Room/Zone Name: ");
                strcat(reportStr, (const char*)zone.roomName);
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;I have a small follow-up question to that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to handle the zone part separately. I got zone details but not room details such as room name etc. Is there a way to get this one also?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 22:52:48 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581270#M9028</guid>
      <dc:creator>sercet65</dc:creator>
      <dc:date>2023-12-20T22:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving Names and Bounding Boxes of Building Elements in ArchiCAD Add-On</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581313#M9034</link>
      <description>&lt;P&gt;There are two problems with your code:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;"&lt;FONT face="courier new,courier"&gt;if (!zone.roomName[0])&lt;/FONT&gt;" checks the opposite you probably wanted to check. Replace it with "&lt;FONT face="courier new,courier"&gt;if (zone.roomName[0])&lt;/FONT&gt;".&lt;/LI&gt;
&lt;LI&gt;You are copying a&amp;nbsp;GS::uchar_t (2-bytes) array to a char (1-byte) array. To have the correct value, convert it to GS::UniString, and then convert it to a C string.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;if (zone.roomName[0]) {
    strcat_s (reportStr, ", Room/Zone Name: ");
    strcat_s (reportStr, GS::UniString (zone.roomName).ToCStr ());
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 07:39:05 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581313#M9034</guid>
      <dc:creator>Viktor Kovacs</dc:creator>
      <dc:date>2023-12-21T07:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving Names and Bounding Boxes of Building Elements in ArchiCAD Add-On</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581409#M9037</link>
      <description>&lt;P&gt;FYI: Everything your&amp;nbsp; asking for can be returned with a short Python script including the 2D and 3D bounding box coordinates - Just saying , it's a lot simpler??&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 16:10:30 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Retrieving-Names-and-Bounding-Boxes-of-Building-Elements-in/m-p/581409#M9037</guid>
      <dc:creator>poco2013</dc:creator>
      <dc:date>2023-12-21T16:10:30Z</dc:date>
    </item>
  </channel>
</rss>

