<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Change a parameter value in memo in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253986#M3388</link>
    <description>&lt;BLOCKQUOTE&gt;wacim wrote:&lt;BR /&gt;
First of all am I doing this right ?
&lt;/BLOCKQUOTE&gt;
Yes, at first sight it looks correct.
&lt;BLOCKQUOTE&gt;wacim wrote:&lt;BR /&gt;
and does this really need an undo scope ?
&lt;/BLOCKQUOTE&gt;
Yes, as Ralph said, all operations which do some kind of element database modification can be executed only from an UndoableCommand.
&lt;BLOCKQUOTE&gt;wacim wrote:&lt;BR /&gt;
because I haven't seen it used in the example for APIAny_OpenParametersID here: &lt;A href="http://archicadapi.graphisoft.com/documentation/apiany_openparametersid" target="_blank"&gt;link&lt;/A&gt;
&lt;/BLOCKQUOTE&gt;
That example calls ACAPI_Element_ChangeDefaults function and you call ACAPI_Element_Change. That's the main difference which explains why you need an undo scope.
&lt;BLOCKQUOTE&gt;wacim wrote:&lt;BR /&gt;
and if so what would it look like ?&lt;BR /&gt;
because this is beyond my comprehension  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_lol.gif" style="display : inline;" /&gt;&lt;BR /&gt;
Thank you for your precious help  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt;
&lt;/BLOCKQUOTE&gt;
Don't be shocked, it's just a little lambda expression (available since C++11)  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_wink.gif" style="display : inline;" /&gt; &lt;BR /&gt;
You just have to change one line: Instead of calling your ManageSelection function directly, call it this way:
&lt;PRE&gt;ACAPI_CallUndoableCommand ("Manage Selection",
	[&amp;amp;] () -&amp;gt; GSErrCode {
		ManageSelection ();

		return NoError;
	});&lt;/PRE&gt;</description>
    <pubDate>Wed, 24 Oct 2018 13:44:28 GMT</pubDate>
    <dc:creator>Tibor Lorantfy</dc:creator>
    <dc:date>2018-10-24T13:44:28Z</dc:date>
    <item>
      <title>Change a parameter value in memo</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253980#M3382</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hi !&lt;BR /&gt;&lt;BR /&gt;I'm still quite new to this but i'm making progress &lt;IMG style="display: inline;" src="https://community.graphisoft.com/legacyfs/online/emojis/icon_cool.gif" border="0" /&gt; &lt;BR /&gt;I need your help to change the value of a parameter in an element's memo.&lt;BR /&gt;i want this to work on an external library's object, that is selected in Archicad.&lt;BR /&gt;I'm able to get the selected items, iterate on them, list the parameters in the memo of each object but don't know how to change them.&lt;BR /&gt;I guess i have to use ACAPI_​Element_​Change ??
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;GSErrCode  ACAPI_Element_Change (
        API_Element*               element,
        const API_Element*         mask,
        const API_ElementMemo*     memo,
        UInt64                     memoMask,
        bool                       withdel
    );
&lt;/PRE&gt;
so that's what i'm doing:
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;ACAPI_ELEMENT_MASK_CLEAR()
ACAPI_ELEMENT_MASK_SET(mask, API_ObjectType, ???); //don't know what to put here
changeErr = ACAPI_Element_Change(&amp;amp;element, objectmask;
changeErr = ACAPI_Element_Change(&amp;amp;element, ??, &amp;amp;memo,  ??, false); //don't know what masks to put
&lt;/PRE&gt;
help &lt;IMG style="display: inline;" src="https://community.graphisoft.com/legacyfs/online/emojis/icon_cry.gif" border="0" /&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Oct 2022 11:36:02 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253980#M3382</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-05T11:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Change a parameter value in memo</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253981#M3383</link>
      <description>Yes, you use &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;ACAPI_Element_Change&lt;E&gt;&lt;/E&gt; to write the change. The easiest option for the element mask is just to change everything using  &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;ACAPI_ELEMENT_MASK_SETFULL&lt;E&gt;&lt;/E&gt;, and the memo mask for changing parameters is &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;APIMemoMask_AddPars&lt;E&gt;&lt;/E&gt;:
&lt;PRE&gt;API_Element mask;
ACAPI_ELEMENT_MASK_SETFULL(mask);
ACAPI_Element_Change(elemData, &amp;amp;mask, elemMemo, APIMemoMask_AddPars, true)&lt;/PRE&gt;

The easiest way to change parameter values is &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;APIAny_ChangeAParameterID&lt;E&gt;&lt;/E&gt;.</description>
      <pubDate>Sat, 20 Oct 2018 09:38:16 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253981#M3383</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2018-10-20T09:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Change a parameter value in memo</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253982#M3384</link>
      <description>Thanks Ralph,&lt;BR /&gt;
I'll look into it tomorrow at work and keep you posted &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_smile.gif" style="display : inline;" /&gt;</description>
      <pubDate>Mon, 22 Oct 2018 08:21:57 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253982#M3384</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-22T08:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Change a parameter value in memo</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253983#M3385</link>
      <description>Grrr Something is still wrong...&lt;BR /&gt;

&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;void ManageSelection(void) {
	API_Element			element, mask;
	API_ElementMemo		memo;
	GSErrCode			err, changeErr;
	
	API_SelectionInfo selectionInfo;
	API_Neig **selNeigs;
	int    ii, nSel, j, nbParams;
	API_AddParType param;
	// Get selected elements (which are all objects from a custom library)
	err = ACAPI_Selection_Get(&amp;amp;selectionInfo, &amp;amp;selNeigs, false); 
	if (err == NoError){
		if (selectionInfo.typeID != API_SelEmpty){
			nSel = BMGetHandleSize((GSHandle)selNeigs) / sizeof(API_Neig);
			API_ParamOwnerType   paramOwner;
			API_ChangeParamType  chgParam;
			API_GetParamsType    getParams;
			for (ii = 0; ii &amp;lt; nSel &amp;amp;&amp;amp; err == NoError; ii++) { //iterating on the selection
				BNZeroMemory(&amp;amp;element, sizeof(element));
				//insert guid in header
				element.header.guid = (*selNeigs[ii]).guid;
				//get the element
				if (ACAPI_Element_Get(&amp;amp;element) == NoError)
					DBPrintf("\n\n GET_ELEMENT OK\n\n");
				else
					DBPrintf("\n\n GET_ELEMENT NOK\n\n");

				if (element.header.hasMemo) {
					BNZeroMemory(&amp;amp;memo, sizeof(memo));
					err = ACAPI_Element_GetMemo(element.header.guid, &amp;amp;memo, APIMemoMask_AddPars);
					if (err == NoError)
						DBPrintf("\n\n GETMEMO OK\n\n");
					else
						ErrorBeep("ACAPI_Element_GetMemo", err);
				}
				//change value of attribute N_panneau of each item in selection
                                // start by filling the param owner
				BNZeroMemory(&amp;amp;paramOwner, sizeof(API_ParamOwnerType));
				paramOwner.libInd = 0;                              //this should be 0 because it's not a library part, it's a placed element
				paramOwner.typeID = API_ObjectID;      // object element
				paramOwner.guid = (*selNeigs[ii]).guid; // placed element guid 
				BNZeroMemory(&amp;amp;getParams, sizeof(API_GetParamsType));
                                
                                // Open a Library Part parameter list to edit
				err = ACAPI_Goodies(APIAny_OpenParametersID, &amp;amp;paramOwner, nullptr);
				if (err == NoError) {
					DBPrintf("\n\n APIAny_OpenParametersID OK");
					BNZeroMemory(&amp;amp;chgParam, sizeof(API_ChangeParamType));
                                        
                                        // Returns the actual (edited) values of a Library Part parameter list opened to edit.
					err = ACAPI_Goodies(APIAny_GetActParametersID, &amp;amp;getParams, nullptr);
					if (err == NoError) {
						DBPrintf("\n\n APIAny_GetActParametersID OK");
						CHCopyC("N_panneau", chgParam.name);  //N_panneau is the parameter's name
						chgParam.realValue = 13.0;   //setting the value to 13 instead of 11
                                                // Changes a value in an opened Library Part parameter list
						err = ACAPI_Goodies(APIAny_ChangeAParameterID, &amp;amp;chgParam, nullptr);
						if (err == NoError) {
							DBPrintf("\n\nAPIAny_ChangeAParameterID OK");
							err = ACAPI_Goodies(APIAny_GetActParametersID, &amp;amp;getParams, nullptr);
						}
						else
							DBPrintf("\n\n APIAny_ChangeAParameterID NOK\n\n");
					}
                                        else
                                                DBPrintf("\n\n APIAny_GetActParametersID NOK");
					err = ACAPI_Goodies(APIAny_CloseParametersID, nullptr, nullptr);
					if (err == NoError) {
						DBPrintf("\n\n APIAny_CloseParametersID OK");
						element.header.typeID = API_ObjectID;
						ACAPI_ELEMENT_MASK_CLEAR(mask);
						ACAPI_ELEMENT_MASK_SETFULL(mask);
						memo.params = getParams.params;
						err = ACAPI_Element_Change(&amp;amp;element, &amp;amp;mask, &amp;amp;memo, APIMemoMask_AddPars, true); 
                                               //the error is here, the error check prints  ACAPI_Element_Change NOK
						if (err == NoError)
							DBPrintf("\n\n ACAPI_Element_Change OK");
						else
							DBPrintf("\n\n ACAPI_Element_Change NOK %d", err);
					}
					else
						DBPrintf("\n\n APIAny_CloseParametersID NOK");
						
				}
				else
					DBPrintf("\n\n APIAny_OpenParametersID NOK\n\n");

			}
			BMKillHandle((GSHandle *)&amp;amp;selNeigs);
		}
		else {
			DBPrintf("\n\n SELECTION_EMPTY \n\n");
		} 
	}
}
&lt;/PRE&gt;
basically i'm selecting elements in archicad then running this function&lt;BR /&gt;
the output i'm getting is:&lt;BR /&gt;
GET_ELEMENT OK&lt;BR /&gt;
GETMEMO OK&lt;BR /&gt;
APIAny_OpenParametersID OK&lt;BR /&gt;
APIAny_GetActParametersID OK&lt;BR /&gt;
APIAny_ChangeAParameterID OK&lt;BR /&gt;
APIAny_CloseParametersID OK&lt;BR /&gt;
ACAPI_Element_Change NOK ,APIERR_NEEDSUNDOSCOPE&lt;BR /&gt;
&lt;BR /&gt;
this is the attribute i want to change: (it's called "Numero de panneau" here but the actual name is "N_panneau") 


First of all am I doing this right ?&lt;BR /&gt;
and does this really need an undo scope ?&lt;BR /&gt;
because I haven't seen it used in the example for APIAny_OpenParametersID here: &lt;A href="http://archicadapi.graphisoft.com/documentation/apiany_openparametersid" target="_blank"&gt;link&lt;/A&gt;&lt;BR /&gt;
and if so what would it look like ?&lt;BR /&gt;
because this:
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;    GSErrCode err = ACAPI_CallUndoableCommand ("Create text",
        [&amp;amp;] () -&amp;gt; GSErrCode {
            return ACAPI_Element_Create (&amp;amp;element, &amp;amp;memo);
        });

    if (err != NoError)
        ErrorBeep ("ACAPI_Element_Create (text)", err);

    ACAPI_DisposeElemMemoHdls (&amp;amp;memo);
&lt;/PRE&gt;
is beyond my comprehension  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_lol.gif" style="display : inline;" /&gt;&lt;BR /&gt;
Thank you for your precious help  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt;</description>
      <pubDate>Wed, 24 Oct 2018 13:04:10 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253983#M3385</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-24T13:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Change a parameter value in memo</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253984#M3386</link>
      <description>Yes, this method has to be called within an undo session. Refer to &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;ACAPI_CallUndoableCommand&lt;E&gt;&lt;/E&gt;. The same applies to any function that changes an element.</description>
      <pubDate>Wed, 24 Oct 2018 13:13:48 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253984#M3386</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2018-10-24T13:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change a parameter value in memo</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253985#M3387</link>
      <description>The whole office heard my shout of joy because this finally worked !&lt;BR /&gt;
THANK YOU !</description>
      <pubDate>Wed, 24 Oct 2018 13:28:26 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253985#M3387</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-24T13:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Change a parameter value in memo</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253986#M3388</link>
      <description>&lt;BLOCKQUOTE&gt;wacim wrote:&lt;BR /&gt;
First of all am I doing this right ?
&lt;/BLOCKQUOTE&gt;
Yes, at first sight it looks correct.
&lt;BLOCKQUOTE&gt;wacim wrote:&lt;BR /&gt;
and does this really need an undo scope ?
&lt;/BLOCKQUOTE&gt;
Yes, as Ralph said, all operations which do some kind of element database modification can be executed only from an UndoableCommand.
&lt;BLOCKQUOTE&gt;wacim wrote:&lt;BR /&gt;
because I haven't seen it used in the example for APIAny_OpenParametersID here: &lt;A href="http://archicadapi.graphisoft.com/documentation/apiany_openparametersid" target="_blank"&gt;link&lt;/A&gt;
&lt;/BLOCKQUOTE&gt;
That example calls ACAPI_Element_ChangeDefaults function and you call ACAPI_Element_Change. That's the main difference which explains why you need an undo scope.
&lt;BLOCKQUOTE&gt;wacim wrote:&lt;BR /&gt;
and if so what would it look like ?&lt;BR /&gt;
because this is beyond my comprehension  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_lol.gif" style="display : inline;" /&gt;&lt;BR /&gt;
Thank you for your precious help  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt;
&lt;/BLOCKQUOTE&gt;
Don't be shocked, it's just a little lambda expression (available since C++11)  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_wink.gif" style="display : inline;" /&gt; &lt;BR /&gt;
You just have to change one line: Instead of calling your ManageSelection function directly, call it this way:
&lt;PRE&gt;ACAPI_CallUndoableCommand ("Manage Selection",
	[&amp;amp;] () -&amp;gt; GSErrCode {
		ManageSelection ();

		return NoError;
	});&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Oct 2018 13:44:28 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253986#M3388</guid>
      <dc:creator>Tibor Lorantfy</dc:creator>
      <dc:date>2018-10-24T13:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Change a parameter value in memo</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253987#M3389</link>
      <description>Thank you Tibor for your explanations&lt;BR /&gt;
as for the " lambda expression" now i know how it's called so i can google it and see how it works...&lt;BR /&gt;
what i did is i searched in all examples folder for use cases of "ACAPI_CallUndoableCommand" and tried to do something similar, which worked but now i'll actually be able to understand  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_lol.gif" style="display : inline;" /&gt;</description>
      <pubDate>Wed, 24 Oct 2018 14:08:39 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Change-a-parameter-value-in-memo/m-p/253987#M3389</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-24T14:08:39Z</dc:date>
    </item>
  </channel>
</rss>

