We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2024-03-24 07:07 AM - last edited on 2024-09-16 02:48 PM by Doreena Deng
Hello,
I'm currently exploring on Archicad API and GDL.
I'm trying to place/create GDL object from an imported library.
I am using the sample add-on template here:
https://github.com/GRAPHISOFT/archicad-addon-cmake
I'm currently using Archicad 26.
I imported a library with GDL (I just found online though its version is Archicad 29. But i can insert the object successfully in the ground floor)
I modified the Add-on sample, to create a GDL object when the custom menu was clicked.
I did follow this topic but I'm having issues whit the APIERR_BADINDEX error message when ACAPI_Element_Create() was called.
https://community.graphisoft.com/t5/Archicad-C-API/How-to-call-and-place-a-GDL-element-with-API-func...
After Create, an error was raised
As you can see, there is no error occurred when searching for the library part (I used the file name to search for the library index. I added a breakpoint before the create element is called)
Hope someone could help me with this.
Regards
2024-03-24 07:23 AM
Just an additional info. I also tried adding the memo in the parameter (commented code) but the same error has been raised
2024-03-24 08:07 AM
I think you are missing ACAPI_CallUndoableCommand() scope.
2024-03-24 03:18 PM
Hello,
I just tried adding this mentioned method but still raising the same error code.
(I'm hoping i did apply the method correctly though)
static GSErrCode MenuCommandHandler (const API_MenuParams *menuParams)
{
switch (menuParams->menuItemRef.menuResID) {
case AddOnMenuID:
switch (menuParams->menuItemRef.itemIndex) {
case AddOnCommandID:
{
/*ExampleDialog dialog;
dialog.Invoke ();*/
API_LibPart m_libpart;
BNZeroMemory(&m_libpart, sizeof(API_LibPart));
m_libpart.typeID = APILib_ObjectID;
const GS::UniString fileName { "05 Basic 2D example 1 AC19.gsm" };
GS::ucscpy(m_libpart.file_UName, fileName.ToUStr());
GSErrCode m_err = ACAPI_LibPart_Search(&m_libpart, false, true);
Int32 m_ParamsCount = 0;
double a, b;
API_AddParType** params = NULL;
m_err = ACAPI_LibPart_GetParams(m_libpart.index, &a, &b, &m_ParamsCount, ¶ms);
API_Element m_element ;
BNZeroMemory(&m_element, sizeof(API_Element));
// GDL Object type
m_element.header.type.typeID = API_ObjectID;
// Library index
m_element.object.libInd = m_libpart.index;
API_ElementMemo m_memo;
BNZeroMemory(&m_memo, sizeof(API_ElementMemo));
m_memo.params = params;
m_err = ACAPI_CallUndoableCommand("Create GDL Element", [&]() -> GSErrCode {
return ACAPI_Element_Create(&m_element, &m_memo);
});
if (m_err != NoError) {
return m_err;
}
}
break;
}
break;
}
return NoError;
}
2024-10-25 04:30 PM
HI! I'm having the same issue. Did someone found the root cause for this?
Thanks in advance
a month ago
Hi, I'd suggest you to check whether the value of element.header.layer is correct, it shouldn't be zero.
HTH.
a month ago
Hi,
I have set the layer to 1, but I'm still facing the issue. Do you any other idea on the reason?
Thanks in advance
a month ago
Hi, then please add one command before you set the library index like below.
HTH.
API_Element m_element;
BNZeroMemory(&m_element, sizeof(API_Element));
// GDL Object type
m_element.header.type.typeID = API_ObjectID;
m_err = ACAPI_Element_GetDefaults (&m_element, NULL);
// Library index
m_element.object.libInd = m_libpart.index;