<?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: The access violation when  create material attribute in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276841#M3298</link>
    <description>Thanks.&lt;BR /&gt;
The code don't work for me.
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;API_AttrTypeID typeID = API_MaterialID;
GSErrCode err = NoError;
API_Attribute attrib={};
API_AttributeDefExt defs={};

attrib.header.typeID = typeID;
//strcpy(attrib.header.name, u8"玻璃 - 蓝色");
GS::UniString materialName(u8"玻璃 - 蓝色");
attrib.header.uniStringNamePtr = &amp;amp;materialName;
err = ACAPI_Attribute_Get(&amp;amp;attrib);
if (err == NoError) {
    err = ACAPI_Attribute_GetDefExt(typeID, attrib.header.index, &amp;amp;defs);
    if (err == APIERR_BADID) {
        BNZeroMemory( &amp;amp; defs, sizeof(API_AttributeDefExt));
        err = NoError;
    }
    //能见度100
    attrib.material.transpPc = 100;
    if (err == NoError) {
        //strcpy(attrib.header.name, name.ToCStr().Get());
        GS::UniString attrName(u8"界线");
        attrib.header.uniStringNamePtr = &amp;amp;attrName;
        err = ACAPI_Attribute_CreateExt( &amp;amp;attrib, &amp;amp;defs);
    }
    ACAPI_DisposeAttrDefsHdlsExt(&amp;amp;defs);
}
&lt;/PRE&gt;

The same problem also occurs.&lt;BR /&gt;
The version of Archicad is 22 and the version of vs is 2015.</description>
    <pubDate>Thu, 05 Dec 2019 01:20:32 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-12-05T01:20:32Z</dc:date>
    <item>
      <title>The access violation when  create material attribute</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276836#M3293</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hi.&lt;BR /&gt;The access violation error occuers when I create a material attribute.&lt;BR /&gt;my code is
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;API_AttrTypeID typeID = API_MaterialID;
API_Attribute		attrib;
	API_AttributeDefExt	defs;
	BNZeroMemory(&amp;amp;attrib, sizeof(API_Attribute));
attrib.header.typeID = typeID;
	strcpy(attrib.header.name, u8"玻璃 - 蓝色");
	err = ACAPI_Attribute_Get(&amp;amp;attrib);
	if (err == NoError) {
		err = ACAPI_Attribute_GetDefExt(typeID, attrib.header.index, &amp;amp;defs);
		if (err == APIERR_BADID) {
			BNZeroMemory(&amp;amp;defs, sizeof(API_AttributeDefExt));
			err = NoError;
		}
		//能见度100
		attrib.material.transpPc = 100;
		if (err == NoError) {
			strcpy(attrib.header.name, name.ToCStr().Get());
			err = ACAPI_Attribute_Create(&amp;amp;attrib,nullptr);
		}
		ACAPI_DisposeAttrDefsHdlsExt(&amp;amp;defs);
	}
&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 29 Sep 2022 07:54:21 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276836#M3293</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-29T07:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: The access violation when  create material attribute</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276837#M3294</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Please use attrib.header.uniStringNamePtr Instead of attrib.header.name, because  the .name is limited in length:&lt;BR /&gt;

&lt;PRE&gt;GS::UniString attrName (u8"玻璃 - 蓝色");
attrib.header.uniStringNamePtr = &amp;amp;attrName;
&lt;/PRE&gt;

and instead of strcpy(attrib.header.name, name.ToCStr().Get()); use:&lt;BR /&gt;

&lt;PRE&gt;attrib.header.uniStringNamePtr = &amp;amp;name;
&lt;/PRE&gt;

Best, Akos</description>
      <pubDate>Tue, 03 Dec 2019 13:43:12 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276837#M3294</guid>
      <dc:creator>Akos Somorjai</dc:creator>
      <dc:date>2019-12-03T13:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: The access violation when  create material attribute</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276838#M3295</link>
      <description>&lt;BLOCKQUOTE&gt;Akos wrote:&lt;BR /&gt;
Hi,&lt;BR /&gt;
&lt;BR /&gt;
Please use attrib.header.uniStringNamePtr Instead of attrib.header.name, because  the .name is limited in length:&lt;BR /&gt;

&lt;PRE&gt;GS::UniString attrName (u8"玻璃 - 蓝色");
attrib.header.uniStringNamePtr = &amp;amp;attrName;
&lt;/PRE&gt;

and instead of strcpy(attrib.header.name, name.ToCStr().Get()); use:&lt;BR /&gt;

&lt;PRE&gt;attrib.header.uniStringNamePtr = &amp;amp;name;
&lt;/PRE&gt;

Best, Akos
&lt;/BLOCKQUOTE&gt;

According to your method,the problem also occuers.</description>
      <pubDate>Wed, 04 Dec 2019 01:08:35 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276838#M3295</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-12-04T01:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: The access violation when  create material attribute</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276839#M3296</link>
      <description>&lt;BLOCKQUOTE&gt;DevJeer wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;Akos wrote:&lt;BR /&gt;
Hi,&lt;BR /&gt;
&lt;BR /&gt;
Please use attrib.header.uniStringNamePtr Instead of attrib.header.name, because  the .name is limited in length:&lt;BR /&gt;

&lt;PRE&gt;GS::UniString attrName (u8"玻璃 - 蓝色");
attrib.header.uniStringNamePtr = &amp;amp;attrName;
&lt;/PRE&gt;

and instead of strcpy(attrib.header.name, name.ToCStr().Get()); use:&lt;BR /&gt;

&lt;PRE&gt;attrib.header.uniStringNamePtr = &amp;amp;name;
&lt;/PRE&gt;

Best, Akos
&lt;/BLOCKQUOTE&gt;

According to your method,the problem also occuers.
&lt;/BLOCKQUOTE&gt;
I notice you've changed the call for creating the material 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_Attribute_CreateExt&lt;E&gt;&lt;/E&gt; and you're passing a &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;API_AttributeDefExt&lt;E&gt;&lt;/E&gt; parameter. Materials don't 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;API_AttributeDefExt&lt;E&gt;&lt;/E&gt;, so perhaps you should be passing just nullptr for that parameter?</description>
      <pubDate>Wed, 04 Dec 2019 09:41:49 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276839#M3296</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2019-12-04T09:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: The access violation when  create material attribute</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276840#M3297</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Here's the code that works for me:&lt;BR /&gt;

&lt;PRE&gt;{
	GS::UniString name (u8"能见度100");

	API_AttrTypeID typeID = API_MaterialID;
	API_Attribute attrib = {};
	API_AttributeDefExt defs = {};
	GSErrCode err = NoError;

	GS::UniString attrName(u8"玻璃 - 蓝色");
	attrib.header.typeID = typeID;
	attrib.header.uniStringNamePtr = &amp;amp;attrName;
	//strcpy(attrib.header.name, u8"玻璃 - 蓝色");
	err = ACAPI_Attribute_Get (&amp;amp;attrib);
	if (err == NoError)
	{
		err = ACAPI_Attribute_GetDefExt (typeID, attrib.header.index, &amp;amp;defs);
		if (err == APIERR_BADID)
		{
			err = NoError;
		}
		//能见度100
		attrib.material.transpPc = 100;
		if (err == NoError)
		{
			attrib.header.uniStringNamePtr = &amp;amp;name;
			//strcpy(attrib.header.name, name.ToCStr().Get());
			err = ACAPI_Attribute_CreateExt (&amp;amp;attrib, &amp;amp;defs);
		}
	}
	ACAPI_DisposeAttrDefsHdlsExt(&amp;amp;defs);

	return;
}&lt;/PRE&gt;

I think the main problem was calling ACAPI_Attribute_Create instead of ACAPI_Attribute_CreateExt.&lt;BR /&gt;
&lt;BR /&gt;
Best, Akos</description>
      <pubDate>Wed, 04 Dec 2019 16:57:34 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276840#M3297</guid>
      <dc:creator>Akos Somorjai</dc:creator>
      <dc:date>2019-12-04T16:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: The access violation when  create material attribute</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276841#M3298</link>
      <description>Thanks.&lt;BR /&gt;
The code don't work for me.
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;API_AttrTypeID typeID = API_MaterialID;
GSErrCode err = NoError;
API_Attribute attrib={};
API_AttributeDefExt defs={};

attrib.header.typeID = typeID;
//strcpy(attrib.header.name, u8"玻璃 - 蓝色");
GS::UniString materialName(u8"玻璃 - 蓝色");
attrib.header.uniStringNamePtr = &amp;amp;materialName;
err = ACAPI_Attribute_Get(&amp;amp;attrib);
if (err == NoError) {
    err = ACAPI_Attribute_GetDefExt(typeID, attrib.header.index, &amp;amp;defs);
    if (err == APIERR_BADID) {
        BNZeroMemory( &amp;amp; defs, sizeof(API_AttributeDefExt));
        err = NoError;
    }
    //能见度100
    attrib.material.transpPc = 100;
    if (err == NoError) {
        //strcpy(attrib.header.name, name.ToCStr().Get());
        GS::UniString attrName(u8"界线");
        attrib.header.uniStringNamePtr = &amp;amp;attrName;
        err = ACAPI_Attribute_CreateExt( &amp;amp;attrib, &amp;amp;defs);
    }
    ACAPI_DisposeAttrDefsHdlsExt(&amp;amp;defs);
}
&lt;/PRE&gt;

The same problem also occurs.&lt;BR /&gt;
The version of Archicad is 22 and the version of vs is 2015.</description>
      <pubDate>Thu, 05 Dec 2019 01:20:32 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/The-access-violation-when-create-material-attribute/m-p/276841#M3298</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-12-05T01:20:32Z</dc:date>
    </item>
  </channel>
</rss>

