<?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: Selecting SEO operators in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Selecting-SEO-operators/m-p/241856#M3806</link>
    <description>Thanks for the replies. Currently I'm using this code in a ButtonClicked function in a modal dialog box. I've managed to fix it so that it functions as required.&lt;BR /&gt;

&lt;PRE&gt;void Dialog::ButtonClicked(const DG::ButtonClickEvent&amp;amp; ev) {

	GS::GSErrCode err = NoError;
	GS::Array&amp;lt;API_Guid&amp;gt;	allElements;

	if (ev.GetSource() == &amp;amp;button)
		Text.SetText(CalculateCount());
	else if (ev.GetSource() == &amp;amp;sButton) {

		if (sButton.GetText() == "Select")

			Text.SetText("Please use the drop down menu to choose\nwhat to select");

		else if (sButton.GetText() == sButton.GetItemText(1)) {

			Text.SetText("Close this dialog to finish selection");

			ACAPI_Element_GetElemList(API_ZombieElemID, &amp;amp;allElements);

			for (const API_Guid&amp;amp; guid : allElements) {

				GS::Array&amp;lt;GS::UniString&amp;gt; guidStrings;
				API_Guid** guid_Operators = nullptr;
				Int32 nLinks = 0;
				err = ACAPI_Element_SolidLink_GetOperators(guid, &amp;amp;guid_Operators, &amp;amp;nLinks);

				if (err != NoError) {
					continue;
				}

				API_Neig** neigs = (API_Neig * *)(BMAllocateHandle(nLinks * sizeof(API_Neig), ALLOCATE_CLEAR, 0));
				for (int i = 0; i &amp;lt; nLinks; i++) {
					(*neigs)&lt;I&gt;.guid = guid_Operators[0]&lt;I&gt;;
				}

				ACAPI_Element_Select(neigs, nLinks, true);
				BMKillHandle(reinterpret_cast&amp;lt;GSHandle*&amp;gt; (&amp;amp;neigs));
				BMhFree(reinterpret_cast&amp;lt;GSHandle&amp;gt; (guid_Operators));

			}
		}
		else if (sButton.GetText() == sButton.GetItemText(2)) {

			Text.SetText("Close this dialog to finish selection");

			ACAPI_Element_GetElemList(API_ZombieElemID, &amp;amp;allElements);

			for (const API_Guid&amp;amp; guid : allElements) {

				GS::Array&amp;lt;GS::UniString&amp;gt; guidStrings;
				API_Guid** guid_Targets = nullptr;
				Int32 nLinks = 0;
				err = ACAPI_Element_SolidLink_GetTargets(guid, &amp;amp;guid_Targets, &amp;amp;nLinks);

				if (err != NoError) {
					continue;
				}

				API_Neig** neigs = (API_Neig * *)(BMAllocateHandle(nLinks * sizeof(API_Neig), ALLOCATE_CLEAR, 0));
				for (int i = 0; i &amp;lt; nLinks; i++) {
					(*neigs)&lt;I&gt;.guid = guid_Targets[0]&lt;I&gt;;
				}

				ACAPI_Element_Select(neigs, nLinks, true);
				BMKillHandle(reinterpret_cast&amp;lt;GSHandle*&amp;gt; (&amp;amp;neigs));
				BMhFree(reinterpret_cast&amp;lt;GSHandle&amp;gt; (guid_Targets));

			}
		}
	}
}&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;BR /&gt;
Cheers.</description>
    <pubDate>Wed, 24 Jul 2019 11:17:09 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-07-24T11:17:09Z</dc:date>
    <item>
      <title>Selecting SEO operators</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Selecting-SEO-operators/m-p/241853#M3803</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I'm trying to find and select all SEO operators. I'm fairly new to C++ and was wondering why this code doesn't work? The commented line crashes Archicad and I'm not sure why.&lt;BR /&gt;
&lt;PRE&gt;GS::GSErrCode err = NoError;
GS::Array&amp;lt;API_Guid&amp;gt; allElements;
		
ACAPI_Element_GetElemList(API_ZombieElemID, &amp;amp;allElements);

for (const API_Guid &amp;amp;guid : allElements) {

	GS::Array&amp;lt;GS::UniString&amp;gt; guidStrings;
	API_Guid **guid_Operators = nullptr;
	Int32 nLinks;
	err = ACAPI_Element_SolidLink_GetOperators(guid, &amp;amp;guid_Operators, &amp;amp;nLinks);

	BMhFree(reinterpret_cast&amp;lt;GSHandle&amp;gt; (guid_Operators));

	if (err != NoError)
		continue;

	GS::Guid nGuid = APIGuid2GSGuid (**guid_Operators); //crashes Archicad

	GS::UniString guidString = nGuid.ToUniString();
	guidStrings.Push(guidString);

	const USize count = guidStrings.GetSize();

	API_Neig** neigs = (API_Neig**)(BMAllocateHandle(count * sizeof(API_Neig), ALLOCATE_CLEAR, 0));
	for (UIndex i = 0; i &amp;lt; count; ++i) {
		(*neigs)&lt;I&gt;.guid = APIGuidFromString(guidStrings&lt;I&gt;.ToCStr().Get());
	}

	ACAPI_Element_Select(neigs, count, true);
	BMKillHandle(reinterpret_cast&amp;lt;GSHandle*&amp;gt; (&amp;amp;neigs));

}&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;
&lt;BR /&gt;If anyone could help that would be great.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Oct 2022 11:24:07 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Selecting-SEO-operators/m-p/241853#M3803</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-05T11:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting SEO operators</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Selecting-SEO-operators/m-p/241854#M3804</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Can you explain here where do you put these C++ lines  to be sure that everyone is able to understand ?</description>
      <pubDate>Fri, 19 Jul 2019 15:10:36 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Selecting-SEO-operators/m-p/241854#M3804</guid>
      <dc:creator>Christophe Fortineau</dc:creator>
      <dc:date>2019-07-19T15:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting SEO operators</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Selecting-SEO-operators/m-p/241855#M3805</link>
      <description>It's because the data you want to inspect is destroyed in this line:
&lt;PRE&gt;BMhFree(reinterpret_cast&amp;lt;GSHandle&amp;gt; (guid_Operators));&lt;/PRE&gt;

That instruction releases the memory used by that variable, so the data is no longer safe or meaningful, hence it crashes when you try to reference it in the following line:
&lt;PRE&gt;GS::Guid nGuid = APIGuid2GSGuid (**guid_Operators);&lt;/PRE&gt;

Don't release the allocated memory until you're finished with it.</description>
      <pubDate>Sat, 20 Jul 2019 08:58:13 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Selecting-SEO-operators/m-p/241855#M3805</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2019-07-20T08:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting SEO operators</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Selecting-SEO-operators/m-p/241856#M3806</link>
      <description>Thanks for the replies. Currently I'm using this code in a ButtonClicked function in a modal dialog box. I've managed to fix it so that it functions as required.&lt;BR /&gt;

&lt;PRE&gt;void Dialog::ButtonClicked(const DG::ButtonClickEvent&amp;amp; ev) {

	GS::GSErrCode err = NoError;
	GS::Array&amp;lt;API_Guid&amp;gt;	allElements;

	if (ev.GetSource() == &amp;amp;button)
		Text.SetText(CalculateCount());
	else if (ev.GetSource() == &amp;amp;sButton) {

		if (sButton.GetText() == "Select")

			Text.SetText("Please use the drop down menu to choose\nwhat to select");

		else if (sButton.GetText() == sButton.GetItemText(1)) {

			Text.SetText("Close this dialog to finish selection");

			ACAPI_Element_GetElemList(API_ZombieElemID, &amp;amp;allElements);

			for (const API_Guid&amp;amp; guid : allElements) {

				GS::Array&amp;lt;GS::UniString&amp;gt; guidStrings;
				API_Guid** guid_Operators = nullptr;
				Int32 nLinks = 0;
				err = ACAPI_Element_SolidLink_GetOperators(guid, &amp;amp;guid_Operators, &amp;amp;nLinks);

				if (err != NoError) {
					continue;
				}

				API_Neig** neigs = (API_Neig * *)(BMAllocateHandle(nLinks * sizeof(API_Neig), ALLOCATE_CLEAR, 0));
				for (int i = 0; i &amp;lt; nLinks; i++) {
					(*neigs)&lt;I&gt;.guid = guid_Operators[0]&lt;I&gt;;
				}

				ACAPI_Element_Select(neigs, nLinks, true);
				BMKillHandle(reinterpret_cast&amp;lt;GSHandle*&amp;gt; (&amp;amp;neigs));
				BMhFree(reinterpret_cast&amp;lt;GSHandle&amp;gt; (guid_Operators));

			}
		}
		else if (sButton.GetText() == sButton.GetItemText(2)) {

			Text.SetText("Close this dialog to finish selection");

			ACAPI_Element_GetElemList(API_ZombieElemID, &amp;amp;allElements);

			for (const API_Guid&amp;amp; guid : allElements) {

				GS::Array&amp;lt;GS::UniString&amp;gt; guidStrings;
				API_Guid** guid_Targets = nullptr;
				Int32 nLinks = 0;
				err = ACAPI_Element_SolidLink_GetTargets(guid, &amp;amp;guid_Targets, &amp;amp;nLinks);

				if (err != NoError) {
					continue;
				}

				API_Neig** neigs = (API_Neig * *)(BMAllocateHandle(nLinks * sizeof(API_Neig), ALLOCATE_CLEAR, 0));
				for (int i = 0; i &amp;lt; nLinks; i++) {
					(*neigs)&lt;I&gt;.guid = guid_Targets[0]&lt;I&gt;;
				}

				ACAPI_Element_Select(neigs, nLinks, true);
				BMKillHandle(reinterpret_cast&amp;lt;GSHandle*&amp;gt; (&amp;amp;neigs));
				BMhFree(reinterpret_cast&amp;lt;GSHandle&amp;gt; (guid_Targets));

			}
		}
	}
}&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;BR /&gt;
Cheers.</description>
      <pubDate>Wed, 24 Jul 2019 11:17:09 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Selecting-SEO-operators/m-p/241856#M3806</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-24T11:17:09Z</dc:date>
    </item>
  </channel>
</rss>

