<?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 Why this code of create element always crashing Archicad app? in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Why-this-code-of-create-element-always-crashing-Archicad-app/m-p/397699#M8567</link>
    <description>&lt;P&gt;Is there anyone could help to fix below code to avoid crashing?.&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="cpp"&gt;=======

ACAPI_Element element;
element.header.guid = guid;
GSErrCode err = ACAPI_Element_Get(&amp;amp;element);
if (err == NoError)
{
API_Element newelement = {};
API_ElementMemo newmemo = {};
API_ElementMemo memo = {};
BNZeroMemory(&amp;amp;newelement, sizeof(API_Element));
BNZeroMemory(&amp;amp;newmemo, sizeof(API_ElementMemo));

newelement.header.type.typeID = element.header.type.typeID;
GSErrCode err = ACAPI_Element_GetDefaults(&amp;amp;newelement, &amp;amp;newmemo);
newelement.header.guid = element.header.guid;
newelement.header.floorInd = element.header.floorInd;
if (element.header.hasMemo &amp;amp;&amp;amp; ACAPI_Element_GetMemo(element.header.guid, &amp;amp;memo, APIMemoMask_All) == NoError)
{
newmemo = memo;
}
err = ACAPI_CallUndoableCommand("Create element", [&amp;amp;]() -&amp;gt; GSErrCode {
return ACAPI_Element_Create(&amp;amp;newelement, &amp;amp;newmemo);
});
}
=============
&lt;/LI-CODE&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 17 Sep 2024 10:48:20 GMT</pubDate>
    <dc:creator>Newbie</dc:creator>
    <dc:date>2024-09-17T10:48:20Z</dc:date>
    <item>
      <title>Why this code of create element always crashing Archicad app?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Why-this-code-of-create-element-always-crashing-Archicad-app/m-p/397699#M8567</link>
      <description>&lt;P&gt;Is there anyone could help to fix below code to avoid crashing?.&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="cpp"&gt;=======

ACAPI_Element element;
element.header.guid = guid;
GSErrCode err = ACAPI_Element_Get(&amp;amp;element);
if (err == NoError)
{
API_Element newelement = {};
API_ElementMemo newmemo = {};
API_ElementMemo memo = {};
BNZeroMemory(&amp;amp;newelement, sizeof(API_Element));
BNZeroMemory(&amp;amp;newmemo, sizeof(API_ElementMemo));

newelement.header.type.typeID = element.header.type.typeID;
GSErrCode err = ACAPI_Element_GetDefaults(&amp;amp;newelement, &amp;amp;newmemo);
newelement.header.guid = element.header.guid;
newelement.header.floorInd = element.header.floorInd;
if (element.header.hasMemo &amp;amp;&amp;amp; ACAPI_Element_GetMemo(element.header.guid, &amp;amp;memo, APIMemoMask_All) == NoError)
{
newmemo = memo;
}
err = ACAPI_CallUndoableCommand("Create element", [&amp;amp;]() -&amp;gt; GSErrCode {
return ACAPI_Element_Create(&amp;amp;newelement, &amp;amp;newmemo);
});
}
=============
&lt;/LI-CODE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 17 Sep 2024 10:48:20 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Why-this-code-of-create-element-always-crashing-Archicad-app/m-p/397699#M8567</guid>
      <dc:creator>Newbie</dc:creator>
      <dc:date>2024-09-17T10:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code of create element always crashing Archicad app?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Why-this-code-of-create-element-always-crashing-Archicad-app/m-p/397727#M8568</link>
      <description>&lt;P&gt;hi newbie, i did not try out your code but i compared it to the maze tutorial. here are my comments:&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;ACAPI_Element element;
element.header.guid = guid; // from where does this element come from? do you want to copy an existing element? 
GSErrCode err = ACAPI_Element_Get(&amp;amp;element); // here you retrieve an existing element, right? 
if (err == NoError)
{
API_Element newelement = {};
API_ElementMemo newmemo = {};
API_ElementMemo memo = {};
BNZeroMemory(&amp;amp;newelement, sizeof(API_Element)); // waht ever you retrieved in the first place will get here deleted 
BNZeroMemory(&amp;amp;newmemo, sizeof(API_ElementMemo)); // same here. after that call you can be sure that the memory of that element is empty
 
newelement.header.type.typeID = element.header.type.typeID; // you are using an variable of a deleted objected. 
GSErrCode err = ACAPI_Element_GetDefaults(&amp;amp;newelement, &amp;amp;newmemo); // you cant retrieve anything of a deleted element. 
newelement.header.guid = element.header.guid;
newelement.header.floorInd = element.header.floorInd;
if (element.header.hasMemo &amp;amp;&amp;amp; ACAPI_Element_GetMemo(element.header.guid, &amp;amp;memo, APIMemoMask_All) == NoError)
{
newmemo = memo;
}
err = ACAPI_CallUndoableCommand("Create element", [&amp;amp;]() -&amp;gt; GSErrCode {
return ACAPI_Element_Create(&amp;amp;newelement, &amp;amp;newmemo);
});
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 08:36:51 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Why-this-code-of-create-element-always-crashing-Archicad-app/m-p/397727#M8568</guid>
      <dc:creator>Joel Buehler</dc:creator>
      <dc:date>2023-09-09T08:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code of create element always crashing Archicad app?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Why-this-code-of-create-element-always-crashing-Archicad-app/m-p/397734#M8570</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A class="" href="https://community.graphisoft.com/t5/user/viewprofilepage/user-id/46313" target="_self"&gt;&lt;SPAN class=""&gt;Joel Buehler&lt;/SPAN&gt;&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;Referring your questions;&lt;/P&gt;&lt;P&gt;1. Yes, the guid from an existing element which I want to copy.&lt;/P&gt;&lt;P&gt;2.&lt;/P&gt;&lt;PRE&gt;BNZeroMemory(&amp;amp;newelement, sizeof(API_Element));&lt;/PRE&gt;&lt;P&gt;This is a newly declare element not element, not sure it should use or not.&lt;/P&gt;&lt;P&gt;BTW, I have try to take those 2 lines of BNZ... out but still&amp;nbsp; crashing. Any suggestion?.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in adv.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 12:05:57 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Why-this-code-of-create-element-always-crashing-Archicad-app/m-p/397734#M8570</guid>
      <dc:creator>Newbie</dc:creator>
      <dc:date>2023-09-09T12:05:57Z</dc:date>
    </item>
  </channel>
</rss>

