<?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: Store additional information for an element in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186225#M5303</link>
    <description>Hi Andor, &lt;BR /&gt;
 &lt;BR /&gt;
I wrote you a short example how to use ACAPI_Element_GetUserData/SetUserData. &lt;BR /&gt;
 
&lt;PRE&gt;// Create an own structure which contains all the necessary informations what you want to store in element's user data 
typedef struct { 
	Int32 myNumbers[5]; 
	char myInfo[API_InfoLen]; 
} MyElementUserData; 
 
// ----------------------------------------------------------------------------- 
bool SetElementUserData (const API_Guid&amp;amp; guid, const API_ElemTypeID&amp;amp; typeID) // Add extra parameters if needed 
{ 
	API_ElementUserData	userData; 
	MyElementUserData**	myUserData = NULL; 
	API_Elem_Head		elemHead; 
	GSErrCode			err = NoError; 
 
	BNZeroMemory (&amp;amp;userData, sizeof (API_ElementUserData)); 
	userData.dataVersion  = 1; 
	userData.platformSign = GS::Act_Platform_Sign; 
	// Set flags if you need: 
	//  userData.flags = APIUserDataFlag_FillWith | APIUserDataFlag_Pickup | APIUserDataFlag_UndoAble | APIUserDataFlag_SkipRecalcAndDraw; 
	userData.dataHdl = BMAllocateHandle (sizeof (MyElementUserData), ALLOCATE_CLEAR, 0); 
	if (userData.dataHdl == NULL) 
		return false; 
 
	myUserData = (MyElementUserData**) (userData.dataHdl); 
	// Fill the allocated userdata as you want: 
	for (Int32 ii = 0; ii &amp;lt; 5; ++ii) { 
		(*myUserData)-&amp;gt;myNumbers[ii] = ii + 1; 
	} 
	sprintf ((*myUserData)-&amp;gt;myInfo, "My Info!"); 
 
	// Attach userdata to the element: 
	BNZeroMemory (&amp;amp;elemHead, sizeof (API_Elem_Head)); 
	elemHead.guid = guid; 
	elemHead.typeID = typeID; 
	err = ACAPI_Element_SetUserData (&amp;amp;elemHead, &amp;amp;userData); 
	if (userData.dataHdl != NULL) 
		BMKillHandle (&amp;amp;userData.dataHdl); 
 
	return err == NoError ? true : false; 
} 
 
// ----------------------------------------------------------------------------- 
bool GetElementUserData (const API_Guid&amp;amp; guid, const API_ElemTypeID&amp;amp; typeID, MyElementUserData** myUserData) 
{ 
	API_ElementUserData	userData; 
	API_Elem_Head		elemHead; 
	GSErrCode			err = NoError; 
 
	BNZeroMemory (&amp;amp;userData, sizeof (API_ElementUserData)); 
 
	// Get userdata from the element: 
	BNZeroMemory (&amp;amp;elemHead, sizeof (API_Elem_Head)); 
	elemHead.guid = guid; 
	elemHead.typeID = typeID; 
	err = ACAPI_Element_GetUserData (&amp;amp;elemHead, &amp;amp;userData); 
	if (err != NoError || userData.dataVersion != 1) { 
		if (userData.dataHdl != NULL) 
			BMKillHandle (&amp;amp;userData.dataHdl); 
		return false; 
	} 
 
	myUserData = (MyElementUserData**) (userData.dataHdl); 
	return true; 
} 
 
// ----------------------------------------------------------------------------- 
// Usage example: 
bool result = false; 
result = SetElementUserData (myGuid, myType); 
 
// ... 
 
MyElementUserData** myUserData = NULL; 
result = GetElementUserData (myGuid, myType, myUserData); 
 
if (result) { 
	// read the userdata 
	Int32 myFirstNumber = (*myUserData)-&amp;gt;myNumbers[0]; 
	// ... 
} 
 
// Don't forget to release the handle after using! 
if (myUserData != NULL) 
	BMKillHandle ((GSHandle*) &amp;amp;myUserData);&lt;/PRE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
Regards, &lt;BR /&gt;
Tibor</description>
    <pubDate>Fri, 04 Jul 2014 13:35:06 GMT</pubDate>
    <dc:creator>Tibor Lorantfy</dc:creator>
    <dc:date>2014-07-04T13:35:06Z</dc:date>
    <item>
      <title>Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186223#M5301</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Which is the best way to concatenate information related to an element? Is it required to create an stl container and use that to store elements and related information, or is it possible to store arrays, variables, etc inside the elements?&lt;BR /&gt;&lt;BR /&gt;Thanks: Andor&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Aug 2023 12:28:32 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186223#M5301</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-01T12:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186224#M5302</link>
      <description>Any short example how to properly use SetUserData and GetUserData?&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
      <pubDate>Fri, 04 Jul 2014 07:28:40 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186224#M5302</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-07-04T07:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186225#M5303</link>
      <description>Hi Andor, &lt;BR /&gt;
 &lt;BR /&gt;
I wrote you a short example how to use ACAPI_Element_GetUserData/SetUserData. &lt;BR /&gt;
 
&lt;PRE&gt;// Create an own structure which contains all the necessary informations what you want to store in element's user data 
typedef struct { 
	Int32 myNumbers[5]; 
	char myInfo[API_InfoLen]; 
} MyElementUserData; 
 
// ----------------------------------------------------------------------------- 
bool SetElementUserData (const API_Guid&amp;amp; guid, const API_ElemTypeID&amp;amp; typeID) // Add extra parameters if needed 
{ 
	API_ElementUserData	userData; 
	MyElementUserData**	myUserData = NULL; 
	API_Elem_Head		elemHead; 
	GSErrCode			err = NoError; 
 
	BNZeroMemory (&amp;amp;userData, sizeof (API_ElementUserData)); 
	userData.dataVersion  = 1; 
	userData.platformSign = GS::Act_Platform_Sign; 
	// Set flags if you need: 
	//  userData.flags = APIUserDataFlag_FillWith | APIUserDataFlag_Pickup | APIUserDataFlag_UndoAble | APIUserDataFlag_SkipRecalcAndDraw; 
	userData.dataHdl = BMAllocateHandle (sizeof (MyElementUserData), ALLOCATE_CLEAR, 0); 
	if (userData.dataHdl == NULL) 
		return false; 
 
	myUserData = (MyElementUserData**) (userData.dataHdl); 
	// Fill the allocated userdata as you want: 
	for (Int32 ii = 0; ii &amp;lt; 5; ++ii) { 
		(*myUserData)-&amp;gt;myNumbers[ii] = ii + 1; 
	} 
	sprintf ((*myUserData)-&amp;gt;myInfo, "My Info!"); 
 
	// Attach userdata to the element: 
	BNZeroMemory (&amp;amp;elemHead, sizeof (API_Elem_Head)); 
	elemHead.guid = guid; 
	elemHead.typeID = typeID; 
	err = ACAPI_Element_SetUserData (&amp;amp;elemHead, &amp;amp;userData); 
	if (userData.dataHdl != NULL) 
		BMKillHandle (&amp;amp;userData.dataHdl); 
 
	return err == NoError ? true : false; 
} 
 
// ----------------------------------------------------------------------------- 
bool GetElementUserData (const API_Guid&amp;amp; guid, const API_ElemTypeID&amp;amp; typeID, MyElementUserData** myUserData) 
{ 
	API_ElementUserData	userData; 
	API_Elem_Head		elemHead; 
	GSErrCode			err = NoError; 
 
	BNZeroMemory (&amp;amp;userData, sizeof (API_ElementUserData)); 
 
	// Get userdata from the element: 
	BNZeroMemory (&amp;amp;elemHead, sizeof (API_Elem_Head)); 
	elemHead.guid = guid; 
	elemHead.typeID = typeID; 
	err = ACAPI_Element_GetUserData (&amp;amp;elemHead, &amp;amp;userData); 
	if (err != NoError || userData.dataVersion != 1) { 
		if (userData.dataHdl != NULL) 
			BMKillHandle (&amp;amp;userData.dataHdl); 
		return false; 
	} 
 
	myUserData = (MyElementUserData**) (userData.dataHdl); 
	return true; 
} 
 
// ----------------------------------------------------------------------------- 
// Usage example: 
bool result = false; 
result = SetElementUserData (myGuid, myType); 
 
// ... 
 
MyElementUserData** myUserData = NULL; 
result = GetElementUserData (myGuid, myType, myUserData); 
 
if (result) { 
	// read the userdata 
	Int32 myFirstNumber = (*myUserData)-&amp;gt;myNumbers[0]; 
	// ... 
} 
 
// Don't forget to release the handle after using! 
if (myUserData != NULL) 
	BMKillHandle ((GSHandle*) &amp;amp;myUserData);&lt;/PRE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
Regards, &lt;BR /&gt;
Tibor</description>
      <pubDate>Fri, 04 Jul 2014 13:35:06 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186225#M5303</guid>
      <dc:creator>Tibor Lorantfy</dc:creator>
      <dc:date>2014-07-04T13:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186226#M5304</link>
      <description>Hi Tibor&lt;BR /&gt;
&lt;BR /&gt;
Is the line "elemHead.typeID = typeID; " required in the example you posted, or is it redundant?&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Paul</description>
      <pubDate>Fri, 08 Aug 2014 13:07:10 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186226#M5304</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-08-08T13:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186227#M5305</link>
      <description>&lt;BLOCKQUOTE&gt;paulk wrote:&lt;BR /&gt;Is the line "elemHead.typeID = typeID; " required in the example you posted, or is it redundant?&lt;/BLOCKQUOTE&gt;

Good question &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_wink.gif" style="display : inline;" /&gt; &lt;BR /&gt;
Everywhere you can identify an element with only the GUID, you don't need the type+index pair anymore. So it's not required.</description>
      <pubDate>Fri, 08 Aug 2014 14:25:12 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186227#M5305</guid>
      <dc:creator>Tibor Lorantfy</dc:creator>
      <dc:date>2014-08-08T14:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186228#M5306</link>
      <description>&lt;BLOCKQUOTE&gt;Everywhere you can identify an element with only the GUID, you don't need the type+index pair anymore. So it's not required.&lt;/BLOCKQUOTE&gt;Thank you.&lt;BR /&gt;
&lt;BR /&gt;
Paul</description>
      <pubDate>Fri, 08 Aug 2014 22:16:49 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186228#M5306</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-08-08T22:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186229#M5307</link>
      <description>Tibor - I have an issue where I am calling the code you posted above from:&lt;BR /&gt;

&lt;PRE&gt;case DG_MSG_CLICK:
			switch (itemId) {
				case 1: // Close Button	
					SetElementUserData(params);
					break;&lt;/PRE&gt;

However - the call to...
&lt;PRE&gt;err = ACAPI_Element_SetUserData (&amp;amp;elemHead, &amp;amp;userData);&lt;/PRE&gt;
kills the ArchiCAD selection system.  So after that call, I can select another ArchiCAD element, but I cannot then select the element the data was saved for in the 3d view (by mouseclicking the element), even with "Arrow" select.  Selection of elements in 2d views is OK though.  err is returning NoError.  If I move the camera in the 3d view, other elements can be selected again.  Rem'ing that line out fixes the problem (but doesn't save the data to the element).  This is AC17 5005.  This appears to be an ArchiCAD bug.&lt;BR /&gt;
&lt;BR /&gt;
Paul</description>
      <pubDate>Sun, 10 Aug 2014 01:17:48 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186229#M5307</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-08-10T01:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186230#M5308</link>
      <description>Does element user data per add-on or can I access the same user data with different add-on?</description>
      <pubDate>Fri, 21 Apr 2017 10:08:57 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186230#M5308</guid>
      <dc:creator>ReignBough</dc:creator>
      <dc:date>2017-04-21T10:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186231#M5309</link>
      <description>&lt;BLOCKQUOTE&gt;ReignBough wrote:&lt;BR /&gt;Does element user data per add-on or can I access the same user data with different add-on?&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
Each Add-On can attach own userdata to an element, but the attached userdata can be accessed only by the owner Add-On.</description>
      <pubDate>Fri, 21 Apr 2017 10:31:08 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186231#M5309</guid>
      <dc:creator>Tibor Lorantfy</dc:creator>
      <dc:date>2017-04-21T10:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: Store additional information for an element</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186232#M5310</link>
      <description>&lt;BLOCKQUOTE&gt;Tibor wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;ReignBough wrote:&lt;BR /&gt;Does element user data per add-on or can I access the same user data with different add-on?&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
Each Add-On can attach own userdata to an element, but the attached userdata can be accessed only by the owner Add-On.&lt;/BLOCKQUOTE&gt;

Additional info: this is for data safety reasons, we don't allow other add-ons to accidentally compromise the data of another add-on.&lt;BR /&gt;
&lt;BR /&gt;
If you have several add-ons, you can still use add-on — add-on communication to query and set the user data.&lt;BR /&gt;
&lt;BR /&gt;
Best, Akos</description>
      <pubDate>Sun, 23 Apr 2017 15:57:23 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Store-additional-information-for-an-element/m-p/186232#M5310</guid>
      <dc:creator>Akos Somorjai</dc:creator>
      <dc:date>2017-04-23T15:57:23Z</dc:date>
    </item>
  </channel>
</rss>

