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

Setting Toolbox mode not working after ArchiCAD stayed open for a very long time

Martin Walter
Enthusiast

I use the following code to insert a new window element of a library part:

 

 

GSErrCode CreateWindowWithTool(const GS::Int32 iLibPartIndex)
{
	// create tool box item
	API_ToolBoxItem toolboxItem;
	BNZeroMemory(&tboxInfo, sizeof(API_ToolBoxItem));
	toolboxItem.type = API_WindowID;
	toolboxItem.variationID = APIVarId_Generic;

	// set tool box mode
	const GSErrCode errorToolBoxMode = ACAPI_Toolbox_SetToolBoxMode(&toolBoxItem);
	if (errorToolBoxMode != NoError)
	{
		return errorToolBoxMode;
	}

	// get element defaults
	API_Element element;
	BNZeroMemory(&element, sizeof(API_Element));
	API_ElementMemo memo;
	BNZeroMemory(&memo, sizeof(API_ElementMemo));

	element.header.type = API_WindowID;

	GSErrCode errorGetDefaults = ACAPI_Element_GetDefaults(&element, &memo);
	if (errorGetDefaults != NoError)
	{
		return errorGetDefaults;
	}

	// change the element defaults
	API_Element elementMask;
	BNZeroMemory(&elementMask, sizeof(API_Element));

	ACAPI_ELEMENT_MASK_SET(elementMask, API_Elem_Head, layer);
	element.header.layer = ACAPI_CreateAttributeIndex(1);		// changed to 'ARCHICAD' layer for each type

	// set parameters
	ACAPI_ELEMENT_MASK_SET(elementMask, API_WindowType, openingBase.libInd);
	element.window.openingBase.libInd = iLibPartIndex;
	ACAPI_ELEMENT_MASK_SET(elementMask, API_WindowType, openingBase.width);
	element.window.openingBase.width = 1.0;
	ACAPI_ELEMENT_MASK_SET(elementMask, API_WindowType, openingBase.height);
	element.window.openingBase.height = 1.0;

	/// set libraray part parameters to memo
	API_ParamOwnerType paramOwner;
	BNZeroMemory(&paramOwner, sizeof(API_ParamOwnerType));
	paramOwner.libInd = iLibPartIndex;
	const GSErrCode errorGoodiesOpen = ACAPI_LibraryPart_OpenParameters(&paramOwner);
	if (errorGoodiesOpen != NoError)
	{
		return errorGoodiesOpen;
	}

	// Returns the actual values of a Library Part parameter list opened to edit
	API_GetParamsType getParams;
	BNZeroMemory(&getParams, sizeof(API_GetParamsType));
	const GSErrCode errorGoodiesGet = ACAPI_LibraryPart_GetActParameters(&getParams);
	if (errorGoodiesGet != NoError)
	{
		return errorGoodiesGet;
	}

	// clear old parameters
	ACAPI_DisposeAddParHdl(&memo.params);

	// set new parameters to memo
	memo.params = getParams.params;

	const GSErrCode errorGoodiesClose = ACAPI_LibraryPart_CloseParameters();
	if (errorGoodiesClose != NoError)
	{
		return errorGoodiesClose;
	}

	// change defaults - element and memo
	const GSErrCode errorChangeDefaults = ACAPI_Element_ChangeDefaults(&element, &memo, &elementMask);

	// clean up
	ACAPI_DisposeElemMemoHdls(&memo);

	return errorChangeDefaults;
}

 

 

The code works fine if I opened ArchiCAD recently and show the insertion tool for the window, which lets me choose the window position:

 

screenshot.jpg

 

But when ArchiCAD was opened for some hours the insertion tool is not shown any more. Maybe it has something to do with Windows hibernate mode. I notice the problem particularly often after waking the computer from hibernate mode. Archicad was left open at the time.

 

I debugged the code above in this case. But the API commands do not return an error. GSErrCode are always NoError but the tool is not shown.

 

Does anybody have an idea?

AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD
0 REPLIES 0