<?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: Attributes selected by name - char and pointers in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235101#M4219</link>
    <description>To be honest, I don't need to use zero-terminated.. but AC seems to need them sometimes. Now I know how to handle them thanks a lot &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt;</description>
    <pubDate>Fri, 24 Aug 2018 12:29:59 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-08-24T12:29:59Z</dc:date>
    <item>
      <title>Attributes selected by name - char and pointers</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235095#M4213</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hi, &lt;BR /&gt;&lt;BR /&gt;I'm trying to select attributes by name. I based it on Example I and II in AttributeGet docs.&lt;BR /&gt;After a while, I had Example 2 working but... It's doing well for all strings which have same beginning. So T, TE, TES, TEST all of them work. I assume its char handling but I'm not sure how to make it work.&lt;BR /&gt;Instead of the header.name I tried UniString pointer but referencing causes AC crashed. &lt;BR /&gt;Here is my try:&lt;BR /&gt;
&lt;PRE&gt;/* Example II -- loop through all attributes of a kind */
API_Attribute  attrib;
	short          nLin, i;
	GSErrCode      err;

	BNZeroMemory(&amp;amp;attrib, sizeof(API_Attribute));
	attrib.header.typeID = API_CompWallID;
	err = ACAPI_Attribute_GetNum(API_CompWallID, &amp;amp;nLin);
	
	for (i = 1; i &amp;lt;= nLin &amp;amp;&amp;amp; err == NoError; i++) {
		attrib.header.index = i;
		err = ACAPI_Attribute_Get(&amp;amp;attrib);

		if (err == NoError) {
			char TTT[100] = "TEST";
			int TTT_Idx;
			
			char AttTxt = *attrib.compWall.head.name;

			if (AttTxt == *TTT) {
				DGAlert(DG_INFORMATION, "ERR1", "ATTRIB GUT", "", "Good");
				TTT_Idx = attrib.compWall.head.index;
			}
&lt;/PRE&gt;
Example 1 didn't work at all. I tried building header but search ends up with an error.&lt;BR /&gt;
&lt;PRE&gt;	//Example I
	API_Attribute attrib;
	BNZeroMemory(&amp;amp;attrib, sizeof(API_Attribute));
	char TTT[256] = "TEST";

	attrib.header.name[256] = *TTT;
	
	err = ACAPI_Attribute_Search(&amp;amp;attrib.header);

	if (err == NoError) {
	char msgStr[512];
	sprintf(msgStr, "[%d] %s", attrib.header.index, attrib.header.name);
	ACAPI_WriteReport(msgStr, true);
	DGAlert(DG_INFORMATION, "ERR1",  msgStr, "", "Good");
	}
	else {
	DGAlert(DG_INFORMATION, "ERR1", "error", "", "Good");
	}&lt;/PRE&gt;
Please help &lt;IMG style="display: inline;" src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" border="0" /&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 30 Nov 2022 09:50:43 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235095#M4213</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-30T09:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Attributes selected by name - char and pointers</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235096#M4214</link>
      <description>You handled the character arrays incorrectly.&lt;BR /&gt;
&lt;BR /&gt;
In "Example II" you made the mistake here:
&lt;BLOCKQUOTE&gt;kzaremba wrote:&lt;BR /&gt;
&lt;PRE&gt;/* Example II -- loop through all attributes of a kind */
...
			char AttTxt = *attrib.compWall.head.name;

			if (AttTxt == *TTT) {
...
&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
This way you copied only the first character of the attrib.compWall.head.name string to the AttTxt variable and in the if statement you compared only the first character of TTT to AttTxt.&lt;BR /&gt;
&lt;BR /&gt;
This would be correct:
&lt;PRE&gt;/* Example II -- loop through all attributes of a kind */
...
			if (strcmp (attrib.compWall.head.name, TTT) == 0) {
...
&lt;/PRE&gt;
You don't need the AttTxt variable and you can compare (char*) strings using strcmp method.&lt;BR /&gt;
&lt;BR /&gt;
But to search attributes with a specific name the ACAPI_Attribute_Search function is recommended, so your other example code fits better for this purpose.&lt;BR /&gt;
You made mistake in your "Example I" here:
&lt;BLOCKQUOTE&gt;kzaremba wrote:&lt;BR /&gt;
&lt;PRE&gt;	//Example I
...
	char TTT[256] = "TEST";

	attrib.header.name[256] = *TTT;
...&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
This way only the first character from TTT will be copied.&lt;BR /&gt;
&lt;BR /&gt;
Use strcpy method to copy the whole string:
&lt;PRE&gt;	//Example I
...
strcpy (attrib.header.name, "TEST");
...
&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Aug 2018 08:58:13 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235096#M4214</guid>
      <dc:creator>Tibor Lorantfy</dc:creator>
      <dc:date>2018-08-17T08:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Attributes selected by name - char and pointers</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235097#M4215</link>
      <description>Hi Tibor, &lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot, I have struggled with chars for a while. Example I works as a charm! &lt;BR /&gt;
&lt;BR /&gt;
I couldn't get Example II working. strcmp gets violet in VS and got this description "strcmp_DISABLED!!!" and compiler error C2065.</description>
      <pubDate>Mon, 20 Aug 2018 15:29:59 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235097#M4215</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-20T15:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Attributes selected by name - char and pointers</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235098#M4216</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Yes, strcmp is disabled in add-on sources. You can use the CHCompareCStrings function instead, which has a similar set of arguments, and produces identical results.&lt;BR /&gt;
&lt;BR /&gt;
Best regards,&lt;BR /&gt;
Dénes</description>
      <pubDate>Tue, 21 Aug 2018 12:53:35 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235098#M4216</guid>
      <dc:creator>dfintha</dc:creator>
      <dc:date>2018-08-21T12:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Attributes selected by name - char and pointers</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235099#M4217</link>
      <description>Hi, thanks a lot for pointing it out. &lt;BR /&gt;
Right now I struggle a lot with char/std::string/GS::String conversions. What is the best practice in your opinion to handle chars and string? Using standard lib or GSRoot? Does it make any difference?</description>
      <pubDate>Wed, 22 Aug 2018 13:24:33 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235099#M4217</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-22T13:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: Attributes selected by name - char and pointers</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235100#M4218</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Using GS::UniString is the preferred method&lt;/B&gt;, as it is used in the API function calls and structures, and it uses UTF-8 encoding.&lt;BR /&gt;
Also, you can use it in a similar fashion as you would use the std::string class, and you can use the GS::UniString::Printf static function instead of sprintf to construct a GS::UniString instance.&lt;BR /&gt;
&lt;BR /&gt;
If you need a zero-terminated C string, you can convert a GS::UniString to a const char * by using the ToCStr method.&lt;BR /&gt;
&lt;BR /&gt;

&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;GS::UniString myStr = "Hello, world!";
// ...
FunctionTakingCStr (myStr.ToCStr ().Get ());
&lt;/PRE&gt;

&lt;BR /&gt;
Best regards,&lt;BR /&gt;
Dénes</description>
      <pubDate>Wed, 22 Aug 2018 14:01:27 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235100#M4218</guid>
      <dc:creator>dfintha</dc:creator>
      <dc:date>2018-08-22T14:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Attributes selected by name - char and pointers</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235101#M4219</link>
      <description>To be honest, I don't need to use zero-terminated.. but AC seems to need them sometimes. Now I know how to handle them thanks a lot &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt;</description>
      <pubDate>Fri, 24 Aug 2018 12:29:59 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Attributes-selected-by-name-char-and-pointers/m-p/235101#M4219</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-24T12:29:59Z</dc:date>
    </item>
  </channel>
</rss>

