cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
2024 Technology Preview Program

2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations

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

Selection handling

vdentello
Advocate

Hello! I've been trying to modify an element selection, but I'm having no success pulling the desired guids. It counts the elements in the selection.

 

ACAPI_Element_GetElemList (API_WallID, &elemList); would work but actually only selects things accoding to the first ever selection. After that, it'll only modify the elements first selected. can't reset selection.

 

element.header.guid = elemList[i].guid; did the trick, selNeigs[I].guid won't, it compiles without warnings though.


I've tried    ACAPI_Selection_GetSelectedElement(&selNeigs, &elemList); but it's not recognized.

 

    API_SelectionInfo    selectionInfo;
    GS::Array<API_Neig> selNeigs;
//    GS::Array<API_Guid> elemList;
    
    ACAPI_Selection_Get (&selectionInfo, &selNeigs, false, false);
    
    GSErrCode err = ACAPI_CallUndoableCommand ("Wall change",
                                               [&] () -> GSErrCode {


//        ACAPI_Selection_GetSelectedElement(&selNeigs, &elemList);           
//             err = ACAPI_Element_GetElemList (API_WallID, &elemList);
        
        for (uint32 i = 0; i < selNeigs.GetSize () && err == NoError; ++i) {
            API_Element element = {};
            element.header.guid = selNeigs[i].guid;
//            element.header.guid = elemList[i].guid;
            
            if (ACAPI_Element_Get (&element) == NoError) {
                /* do what you want */
                
                ACAPI_Element_Get (&element);
//                FlipWall(element.header.guid);

 

Archicad User Since 2013
GDL Developer
Experimenting with API
from Brazil
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
vdentello
Advocate

Made it work with a lot of trial and error. 
This time, it was able to request the guids from the selected Neigs without using:

ACAPI_Selection_GetSelectedElement

 

Actually, I declared GSErrCode err = NoError;  and then just tried err = ACAPI_Selection_Get instead and it did the trick. For reference, the way it actually worked (selection_get will also work before callUndoable):

    GSErrCode err = NoError;
    API_SelectionInfo   selectionInfo;
    GS::Array<API_Neig> selNeigs;



    err = ACAPI_CallUndoableCommand ("Wall change",
                                               [&] () -> GSErrCode {

    err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, false, false);

        for (uint32 i = 0; i < selNeigs.GetSize () && err == NoError; ++i) {
            API_Element element = {};
            element.header.guid = selNeigs[i].guid;

            if (ACAPI_Element_Get (&element) == NoError) {
                /* do what you want */
                
                ACAPI_Element_Get (&element);
    //                FlipWall(element.header.guid);

 

Archicad User Since 2013
GDL Developer
Experimenting with API
from Brazil

View solution in original post

4 REPLIES 4
Solution
vdentello
Advocate

Made it work with a lot of trial and error. 
This time, it was able to request the guids from the selected Neigs without using:

ACAPI_Selection_GetSelectedElement

 

Actually, I declared GSErrCode err = NoError;  and then just tried err = ACAPI_Selection_Get instead and it did the trick. For reference, the way it actually worked (selection_get will also work before callUndoable):

    GSErrCode err = NoError;
    API_SelectionInfo   selectionInfo;
    GS::Array<API_Neig> selNeigs;



    err = ACAPI_CallUndoableCommand ("Wall change",
                                               [&] () -> GSErrCode {

    err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, false, false);

        for (uint32 i = 0; i < selNeigs.GetSize () && err == NoError; ++i) {
            API_Element element = {};
            element.header.guid = selNeigs[i].guid;

            if (ACAPI_Element_Get (&element) == NoError) {
                /* do what you want */
                
                ACAPI_Element_Get (&element);
    //                FlipWall(element.header.guid);

 

Archicad User Since 2013
GDL Developer
Experimenting with API
from Brazil

Hi Vítor,


ACAPI_Selection_GetSelectedElement is only available since AC27. So if you are using <=AC26 you'll have to use ACAPI_Selection_Get as you've found.

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com

In any case, ACAPI_Selection_GetSelectedElement would have to take an input from an auxiliary function as it seems? ACAPI_Selection_Get actually outs outs the neighs, that could be converted.

Archicad User Since 2013
GDL Developer
Experimenting with API
from Brazil

Ups sry! you are right. ACAPI_Selection_Get stays the same in AC27.

The AC26 equivalent to ACAPI_Selection_GetSelectedElement is ACAPI_Goodies(APIAny_GetSelectedElementID,...).

 

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com