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

Changing elements

vdentello
Advocate

Hello! I've been struggling to make things work here.

The code builds, the command runs without trouble and I get the dialog at the end. But I get no changes to my element. can't figure out what's still missing. I've used most of the code from the examples.


I'm not using 'ACAPI_Element_Edit', cause I warns that: 

No matching function for call to 'ACAPI_Element_Edit'

 

#include "basicgeometry.h"

 

 

void EditWall ()
{
    API_Element            element, mask;
    API_ElementMemo        memo;
//    GSErrCode err = NoError;
    
    element = {};
    memo = {};
    
    ACAPI_Element_Get (&element);
    ACAPI_Element_GetMemo (element.header.guid, &memo);
    
    ACAPI_ELEMENT_MASK_CLEAR (mask);
    ACAPI_ELEMENT_MASK_SET (mask, API_WallType, thickness);
    element.wall.thickness = 1.0;
    
//    ACAPI_Element_Edit(&element, &mask);

    ACAPI_Element_Change (&element, &mask, &memo, 0, true);
    
    DG::InformationAlert ("Exit", "Click ok to continue", "OK");
}

 

 

 

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

Hi Vítor,

The element.header.guid is empty since you didn't assign anything.
So both ACAPI_Element_Get and ACAPI_Element_GetMemo won't know which element to look for.
You'll have to get a guid of a wall first.

 

There are a lot of possibilities for this.

E.g. iterate through all walls with ACAPI_Element_GetElemList or get the guid from a selection with ACAPI_Selection_Get

There's a good code example for it on the linked documentation page.

 

The rest of your code seems fine for changing the wall thickness.


If you want to use ACAPI_Element_Edit you will have to pass different arguments as documented here: https://graphisoft.github.io/archicad-api-devkit/group___element.html#gaf661e412a0e3a3f6979444c67ec6...

Best,
Bernd

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: bschwb.com
vdentello
Advocate

It finally worked!
Another very important detail that was missing, from the beginning, was that it needs a ACAPI_CallUndoableCommand before everything, followed by a ACAPI_DisposeElemMemoHdls as it seems. Found many occurrences of this issue in the forum. I guess that should be more explicit within the first steps.

Archicad User Since 2013
GDL Developer
Experimenting with API
from Brazil
poco2013
Mentor

Another point -- for cleaner code: API_ElementMemo  is not required and should be replaced with nullptr. It's only required if your going to replace some of the attributes in the Memo structure.

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!