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.

Create a custom paint tool

mats1
Participant

Hi all, i would like to create a tool where users can select attributes (materials) and paint them onto elements of their choosing. The problem i am having right now is that when using

 

 

 

ACAPI_Notification_CatchSelectionChange

 

 

 

 

 

 

 

static GSErrCode SelectionChangeHandler(const API_Neig* selElemNeig) {

    // Pseudo code
    if (selElemNeig->neigID != APINeig_None) {
        auto err = ACAPI_CallUndoableCommand("Change element", []() {
            return ACAPI_Element_Change(...);
        });
        // err is Unkown Error when printed
        // after this the SelectionChangeHandler is being called repeatedly indefinitely
    }
    else
        ACAPI_WriteReport("All elements deselected", false);

    return NoError;
}   // SelectionChangeHandler

 

 

 

 I am unable to update the element inside of the callback, im guessing based of the docs its not allowed to do DB operations on a seperate thread.

I also tried using 

 

 

 

        API_Neig clickedNeig;

        ClickAnElem("Click an elem to select/deselect", API_ZombieElemID, &clickedNeig);

        auto err = ACAPI_CallUndoableCommand("Change element", []() {
            return ACAPI_Element_Change(...);
            });

 

 

 

Which works but i want to be able to select many things and paint accordingly. having this solution in a while loop ofcourse blocks the UI so the user cannot interact with other panels visible until ESC key is pressed. I have buttons in my to stop painting or changing colors.


3 REPLIES 3
Barry Kelly
Moderator

Does this have to be an API solution?

Can you just use the surface painter tool that is already there in Archicad?

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
mats1
Participant

Hi, unfortunately this is not possible since i want to both create the colors and paint them in the same palette. I understand the surface painter is exactly for picking colors and painting elements but i would like to create my own, and it seems to be impossible with the available APIs.

 

Mats.

mats1
Participant

This is now resolved. The trick was when we changed the element the user had selected this function was called again and became an infinite repeating loop. Checking if the same element was updated twice solved it.

static GSErrCode SelectionChangeHandler(const API_Neig* selElemNeig) {

    // Pseudo code
    if (selElemNeig->neigID != APINeig_None) {
        auto err = ACAPI_CallUndoableCommand("Change element", []() {
            return ACAPI_Element_Change(...);
        });
        // err is Unkown Error when printed
        // after this the SelectionChangeHandler is being called repeatedly indefinitely
    }
    else
        ACAPI_WriteReport("All elements deselected", false);

    return NoError;
}   // SelectionChangeHandler