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.

Changing memo.TextContent causes text scale issues?

cfranklin
Newcomer
Hi,

I'm attempting to change the content of a text object, and can alter it successfully like so:

GSErrCode JHP_TextToCase(JHP_Text_Case textCase)
{
	GSErrCode				err;
	API_Neig				**selNeigs;
	API_ElementMemo		memo;
	API_Element				element, mask;

	selNeigs = (API_Neig**)BMAllocateHandle(sizeof(API_Neig), ALLOCATE_CLEAR, 0);
	err = JHP_GetSelectionOrSelect_Mult(&selNeigs);

	UInt32 nSel = BMGetHandleSize((GSHandle)selNeigs) / sizeof(API_Neig);

	err = ACAPI_Element_Select(selNeigs, nSel, true);

	for (UInt32 i = 0; i < nSel; ++i) {

		BNZeroMemory(&element, sizeof(API_Element));
		BNZeroMemory(&memo, sizeof(API_ElementMemo));

		element.header.guid = (*selNeigs).guid;

		element.header.typeID = Neig_To_ElemID((*selNeigs).neigID);

		if (element.header.typeID != API_TextID) { continue; }

		if (!ACAPI_Element_Filter(element.header.guid, APIFilt_IsEditable))
		{
			WriteReport_Alert("Object not editable");
			break;
		}

		if (ACAPI_Element_Get(&element) != NoError) {  continue; }

		ACAPI_ELEMENT_MASK_CLEAR(mask);
		
		if (ACAPI_Element_GetMemo(element.header.guid, &memo, APIMemoMask_TextContent) != NoError) {  continue; }

		JHP_ModifyTextCase(textCase, &memo);
		
		err = ACAPI_Element_Change(&element, &mask, &memo, APIMemoMask_TextContent, true);

		ACAPI_DisposeElemMemoHdls(&memo);
	}

	BMKillHandle((GSHandle*)&selNeigs);

	return err;
}
This code was created following examples in the Element_Modify.cpp, but when I use this code to change the TextContent, the text object's scale becomes far smaller without altering the element.text.size or anything similar.

The function
JHP_ModifyTextCase(textCase, &memo);
merely changes the textContent of the memo to upper or lowercase.

When the function is called on text that has Fixed State: Scale Independent(Paper Size) setting, the text does not change size. However, if the text is set to Fixed State: Scale with plan (Model Size), then the text reduces in size greatly. Currently, the text goes from 2 1/2" to 15/64" using the above code, when it seems nothing should resize it.

If I try to get the current text size using
element.text.size
, it appears to report the size and if I set the element.text.size in the mask, it still sets the size to a number far lower than it currently is.

Is this a bug? does text scale have to be recalculated somehow every time the content alone is changed?

In none of the examples did I see this written any differently or bothering with scale.

Any information would be great,

Thanks.
1 REPLY 1
cfranklin
Newcomer
Found the solution.

Turns out, you need to write the memo.Paragraph back into the element to keep the text the same scale, even if you are only altering the textContent.

So changing the APIMemoMask_TextContent being passed into the Get memo call as well as the ElementChange call fixes the issue if the mask instead includes the paragraph.

UInt32 memoMask = 0;
memoMask |= APIMemoMask_TextContent;
memoMask |= APIMemoMask_Paragraph;
Learn and get certified!