We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

ACAPI_Element_Change

Anonymous
Not applicable
I started with the Do_Word_Edit function found in ..\Examples\Element_Test in the Element_Modify.cpp file. I am using the true part of (mode==1) of the if to "Click a word to change its content". My intent is to change selected text to upper case. All existing code is untouched until after
"strcpy(*memo.textContent, text);"

Then:

		strcpy(*memo.textContent, text);

<my modification>
		// Test getting the memo of the existing text
		ACAPI_Element_GetMemo(element.header.guid, &memo, APIMemoMask_TextContent);
		CHtoUpper(*memo.textContent);
		JHP_Msg(*memo.textContent);  // displays selected text with conversion to upper case
</my modification>

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

<my modification>
		if (err != NoError) // always true.
		{
			JHP_Msg("There is an error.");
			JHP_Msg((strerror(err))); // Error message in plain English is "Unknown error"
		}
</my modification>

		ACAPI_DisposeElemMemoHdls(&memo);

I am having trouble with ACAPI_Element_Change. Since I believe my modifications are only the conversion to upper case and verification of error after ACAPI_Element_Change, I am not quite sure what I did to break it. In my mind, the ACAPI_Element_Change is operating just the same as it was used in the example from the Element_modify.cpp file.

What am I missing?

Thanks -
chris
5 REPLIES 5
Anonymous
Not applicable
So it seems that adding this:

 return ACAPI_CallUndoableCommand("JHP Menu Command Function",
	[&]() -> GSErrCode {

to wrap my menu load that does the function call solves the problem.

And after I successfully convert my selected text to upper case, I can ^Z back to lower case. Not what I would expect with 'ACAPI_CallUndoableCommand'.

Can someone please explain???

thanks - chris
Ralph Wessel
Mentor
Functions like ACAPI_Element_Change cause changes to the database which the user should be able to undo. In order for these functions to work, you need to enclose them in ACAPI_CallUndoableCommand to prepare ARCHICAD for undoable changes. If you don't, ARCHICAD will refuse to complete the function and return an error.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Thanks for the insight Ralph. It just sounds a little counter-intuitive. I feel like getting this first function call from my menu sets up a good template for the others that will follow. Thanks again for your help.
- chris
Ralph Wessel
Mentor
chrisgilmer wrote:
Thanks for the insight Ralph. It just sounds a little counter-intuitive
It might help if you think about it as a database transaction. Marking the beginning and end of a transaction allows that specific action to be rolled back, in this case by the user requesting an 'Undo'
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
I get the database marks and thanks for emphasizing that part of it.

I just realized I was putting emphasis on the wrong syllables. I was reading it as "I am calling a command that does not respond to ^Z" instead of "I am calling a command that allows ^Z, therefore it is undoable".

"Let's eat grandma" vs. "Let's eat, grandma".

Thanks again -
chris