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.

APIERR_BADINDEX error when creating element using GDL object library index

kristkun
Participant

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)

kristkun_0-1711259892450.png


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...

kristkun_0-1711260716496.png


After Create, an error was raised

kristkun_1-1711260835101.png

 

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

3 REPLIES 3
kristkun
Participant

Just an additional info. I also tried adding the memo in the parameter (commented code) but the same error has been raised

Miha Nahtigal
Advocate

I think you are missing ACAPI_CallUndoableCommand() scope. 

BIMquants.comBETA - Quantities and Costs Estimation with Archicad AddOn :: rushing to publish a beta preview
kristkun
Participant

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, &params);

						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;
}
Learn and get certified!