BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

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

First add-on questions

julienK
Advocate
Hi, I’m trying to write my first add-on for Archicad and after a few days of going through the API and exemples I have to admit I’m going nowhere. I’ve been writing GDL objects for years and a few simple programs in C++ but writing full fledge Add-Ons seems to be a different kind of beast.

What I’m trying to do:

I have a residential building with n numbers of apartments. Each apartment has a set of zones for each room with the same zone number.

I want to write an add-on that would create a label or textbox that displays the sum of the surfaces for each apartment, ie each group of zones with the same zone number and place it on the floor plan.


The workflow I’m looking for would be either:

- having the user select the zones in the project manually and the add-on would then do it’s thing

- have a popup menu to set some criteria (specify layer or zone category) click a button and let the add-on look for the zones and do its thing.


So far all I got to manage is create my menu and palette in archicad.


My first questions:

1. In the .grc file in the interface_Functions exemple in the API you have :

'STR#' 32500 "Strings for the Menu" {
/* [ ] */ "Test"
/* [ ] */ "Interface Functions"
/* [ 1] */ "Open Control Palette^ES^EE^EI^E3^ED^EW^EL"
/* [ 2] */ "Show Palette^ES^EE^EI^G^ED^EW^EL" /* grayed by default */
/* [ 3] */ "-"
/* [ 4] */ "Get a Point^ES^EE^EI^E3^ED^EW^EL^R" /* repeatable command */
/* [ 5] */ "Get a Line^ES^EE^EI^E3^ED^EW^EL^R"
/* [ 6] */ "Get an Arc^ES^EE^EI^E3^ED^EW^EL^R"

What is this part : ^ES^EE^EI^E3^ED^EW^EL ? I'm assuming it has something to do with the user inputs expected after the menu is clicked, is that correct ?
Is it explained in the API ? I couldn't fin anything about it.


2. How do you interact with elements already placed in your project?

Depending on the workflow described above, that means:

- What function in the API let the user select some elements on the floor plan, or what is the general process to ask the user to select some elements

- If I want to do that automatically, how does the Add-On can search through the project to find zones in it ?




Thank you in advance for the answers.
2 REPLIES 2
Ralph Wessel
Mentor
juliencuadra wrote:
What is this part : 1. ^ES^EE^EI^E3^ED^EW^EL ?
Anything starting with ^ in a menu item is specifying a context in which that menu is relevant. For example, "^E3" means "enabled in 3D window". You can find documentation on this here: http://archicadapi.graphisoft.com/documentation/required-resources
juliencuadra wrote:
What is this part : 1. 2. How do you interact with elements already placed in your project?
- What function in the API let the user select some elements on the floor plan, or what is the general process to ask the user to select some elements
- If I want to do that automatically, how does the Add-On can search through the project to find zones in it ?
The best approach generally is for the user to select some elements first and then select a menu to perform some action on the selection. That's how most tools already work in Archicad.

Part of the problem getting started is that most of the API is just plain C, or a bit of "C with classes" rather than C++. We've written a modern C++ wrapper, so we collect editable, selected zones from the floor plan like this:
auto selectedZones = plan.getSelection({Drawing::Filter::isEditable, Zone::ID});
GS' sample code for collecting elements is much more verbose: http://archicadapi.graphisoft.com/documentation/acapi_selection_get
GS::Array<API_Guid>& inds
GSErrCode            err;
API_SelectionInfo    selectionInfo;
API_Elem_Head        tElemHead;
GS::Array<API_Neig>  selNeigs;
err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, true);
BMKillHandle ((GSHandle *) &selectionInfo.marquee.coords);
if (err == APIERR_NOSEL)
    err = NoError;
if (selectionInfo.typeID != API_SelEmpty) {
    // collect indexes of selected dimensions
    UInt32 nSel = BMGetHandleSize ((GSHandle) selNeigs) / sizeof (API_Neig);
    for (const API_Neig& selNeig : selNeigs) {
        tElemHead.typeID = Neig_To_ElemID (selNeig.neigID);
        if (tElemHead.typeID != API_DimensionID)
            continue;
        if (!ACAPI_Element_Filter (selNeig.guid, APIFilt_IsEditable))
            continue;
        tElemHead.guid = selNeig.guid;
        if (ACAPI_Element_GetHeader (&tElemHead) != NoError)
            continue;

        // Add dimension to the array
        inds.Push (tElemHead.guid);
    }
}
Ralph Wessel BArch
julienK
Advocate
Thank you Ralph.
Learn and get certified!