<?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: How to use AcDbEvalGraph::getAllNodes() in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12205806#M1498</link>
    <description>Yes, I meant "when it goes out of scope".&lt;BR /&gt;I have set breakpoint and next line by line, I can safely go through line 35 (in the original code), but the program stopped at the last line, line 36, the line has only closing parenthesis.&lt;BR /&gt;In the AutoCAD's command line, the number of nodes was also printed.</description>
    <pubDate>Wed, 30 Aug 2023 04:08:48 GMT</pubDate>
    <dc:creator>smx_khang</dc:creator>
    <dc:date>2023-08-30T04:08:48Z</dc:date>
    <item>
      <title>How to use AcDbEvalGraph::getAllNodes()</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12195592#M1494</link>
      <description>&lt;P&gt;Hello everyone&lt;/P&gt;&lt;P&gt;I'm working with&amp;nbsp;AcDbEvalGraph, my task is get and print number of node in a graph.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I maked a function as below, that can successully build and load into AutoCAD. But when I run it, I faced an error.&lt;/P&gt;&lt;P&gt;In debug mode, VS said: "A breakpoint instruction (__debugbreak() statement or a similar call) was executed in acad.exe"&lt;/P&gt;&lt;P&gt;Why that error occurs? Did I have any misstake?&lt;/P&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;&lt;LI-CODE lang="cpp"&gt;void test() {
    Acad::ErrorStatus es;
    AcDbObjectId objId;

    ads_name name; ads_point p;
    if (acedEntSel(_T("\nSelect block reference: "), name, p) != RTNORM)
        return;

    acdbGetObjectId(objId, name);
    AcDbBlockReference* pBlkRef;
    es = acdbOpenObject(pBlkRef, objId, AcDb::kForRead, false);
    if (es != Acad::eOk) return;

    AcDbDynBlockReference dynBlk(objId);
    AcDbBlockTableRecordPointer pBTR(dynBlk.dynamicBlockTableRecord(), AcDb::kForRead);
    if (pBTR.openStatus() != Acad::eOk) return;

    // Open Dictionary of Block Table Record
    objId = pBTR-&amp;gt;extensionDictionary();
    AcDbDictionary* pDic;
    es = acdbOpenObject(pDic, objId, AcDb::kForWrite, false);
    if (es != Acad::eOk) return;

    // Open EvalGraph
    es = pDic-&amp;gt;getAt(_T("ACAD_ENHANCEDBLOCK"), objId);
    if (es != Acad::eOk) return;
    AcDbEvalGraph* graph;
    es = acdbOpenObject(graph, objId, AcDb::kForWrite, false);
    if (es != Acad::eOk) return;

    // Get length of NodeIdArray
    AcDbEvalNodeIdArray nodes;
    es = graph-&amp;gt;getAllNodes(nodes);
    if (es != Acad::eOk) return;
    acutPrintf(_T("\nLength: %d", nodes.length()));
}&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;&lt;P&gt;I'm using AutoCAD 2023.&lt;/P&gt;&lt;P&gt;Visual Studio 2022 with CPP project is not generated by ObjectARX Wizard.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2023 03:03:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12195592#M1494</guid>
      <dc:creator>smx_khang</dc:creator>
      <dc:date>2023-08-25T03:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use AcDbEvalGraph::getAllNodes()</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12195908#M1495</link>
      <description>&lt;P&gt;You have wrong braces in &lt;FONT face="courier new,courier"&gt;acutPrintf(_T("\nLength: %d", nodes.length()));&amp;nbsp;&lt;/FONT&gt;&amp;nbsp;&lt;BR /&gt;It should be&amp;nbsp;&lt;FONT face="courier new,courier"&gt;acutPrintf( _T("\nLength: %d"), nodes.length() );&lt;BR /&gt;&lt;/FONT&gt;I tested with this fix and it worked fine on AutoCAD 2022.&lt;/P&gt;
&lt;P&gt;If you still get problems try to open&amp;nbsp;&lt;FONT face="courier new,courier"&gt;pDic and&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new, courier"&gt;graph kForRead&lt;/FONT&gt; only instead of &lt;FONT face="courier new, courier"&gt;kForWrite&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2023 07:22:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12195908#M1495</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2023-08-25T07:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to use AcDbEvalGraph::getAllNodes()</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12203155#M1496</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/845950"&gt;@tbrammer&lt;/a&gt;&amp;nbsp; Thanks for your answer. And sorry for my late reply.&lt;BR /&gt;I checked the syntax of the program again, I also tried opening the objects to read-only, but the problem is not solved. (That error arises when the system tries to delete the arr object).&lt;BR /&gt;Then I did some research and found out that the problem seems to come from the way the array object is declared.&lt;BR /&gt;Just do this, everything works fine&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// Get length of NodeIdArray
AcDbEvalNodeIdArray* nodes = new AcDbEvalNodeIdArray();
es = graph-&amp;gt;getAllNodes(*nodes);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 05:13:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12203155#M1496</guid>
      <dc:creator>smx_khang</dc:creator>
      <dc:date>2023-08-29T05:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use AcDbEvalGraph::getAllNodes()</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12203364#M1497</link>
      <description>&lt;P&gt;In AutoCAD 2024 I don't get any exceptions with the original test code lines:&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;AcDbEvalNodeIdArray nodes;
es = graph-&amp;gt;getAllNodes(nodes);&lt;/LI-CODE&gt;
&lt;P&gt;The call itself should be safe with an&amp;nbsp;&lt;FONT face="courier new,courier"&gt;AcDbEvalNodeIdArray&lt;/FONT&gt; on the stack.&lt;/P&gt;
&lt;P&gt;You wrote: "&lt;EM&gt;That error arises when the system tries to delete the arr object&lt;/EM&gt;"&lt;/P&gt;
&lt;P&gt;Do you mean that it arises, when &lt;FONT face="courier new,courier"&gt;nodes&lt;/FONT&gt; goes out of scope?&lt;/P&gt;
&lt;P&gt;Or did you pass the pointer&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;nodes&lt;/FONT&gt;&amp;nbsp;to another function that calls &lt;FONT face="courier new,courier"&gt;delete&lt;/FONT&gt; for the pointer?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 07:28:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12203364#M1497</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2023-08-29T07:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use AcDbEvalGraph::getAllNodes()</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12205806#M1498</link>
      <description>Yes, I meant "when it goes out of scope".&lt;BR /&gt;I have set breakpoint and next line by line, I can safely go through line 35 (in the original code), but the program stopped at the last line, line 36, the line has only closing parenthesis.&lt;BR /&gt;In the AutoCAD's command line, the number of nodes was also printed.</description>
      <pubDate>Wed, 30 Aug 2023 04:08:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12205806#M1498</guid>
      <dc:creator>smx_khang</dc:creator>
      <dc:date>2023-08-30T04:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to use AcDbEvalGraph::getAllNodes()</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12205867#M1499</link>
      <description>&lt;P&gt;IMHO, you should be consistent with using smart pointers, so you know everything is closed if there’s an early return&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 05:14:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12205867#M1499</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2023-08-30T05:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to use AcDbEvalGraph::getAllNodes()</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12206062#M1500</link>
      <description>&lt;P&gt;Probably a silly question: Did you &lt;FONT face="courier new,courier"&gt;delete&lt;/FONT&gt; the array without problems?&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;AcDbEvalNodeIdArray* nodes = new AcDbEvalNodeIdArray();
es = graph-&amp;gt;getAllNodes(*nodes);
// print nodes ...
delete nodes;&lt;/LI-CODE&gt;
&lt;P&gt;I really can't imagine why it should make a difference to use a &lt;FONT face="courier new,courier"&gt;AcDbEvalNodeArray&lt;/FONT&gt; on the stack or an array on the heap created with &lt;FONT face="courier new,courier"&gt;new&lt;/FONT&gt;&amp;nbsp;- unless there are other general stack memory problems - like a wrong &lt;FONT face="courier new,courier"&gt;acutPrintf()&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;Do you also get the exception if you register your function &lt;FONT face="courier new,courier"&gt;void test()&lt;/FONT&gt;&amp;nbsp;with &lt;FONT face="courier new,courier"&gt;acutPrintf()&lt;/FONT&gt;fix and &amp;nbsp;&lt;FONT face="courier new,courier"&gt;nodes&amp;nbsp;&lt;/FONT&gt;on stack&amp;nbsp;as command and execute it?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 07:15:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12206062#M1500</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2023-08-30T07:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use AcDbEvalGraph::getAllNodes()</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12208486#M1501</link>
      <description>I was a bit confused.&lt;BR /&gt;It's embarrassed to say that I forgot to delete the pointer nodes.&lt;BR /&gt;As you said, there is no difference between using pointers and not. When I deleted the pointer using delete operator, the same error happened (Even if I commented-out acutPrintf)&lt;BR /&gt;I also registered my test() as a command and executed it.</description>
      <pubDate>Thu, 31 Aug 2023 03:28:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12208486#M1501</guid>
      <dc:creator>smx_khang</dc:creator>
      <dc:date>2023-08-31T03:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to use AcDbEvalGraph::getAllNodes()</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12208813#M1502</link>
      <description>&lt;P&gt;Although&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8575899"&gt;@daniel_cadext&lt;/a&gt;&amp;nbsp;already gave the advice to use smart pointers consistently I didn't realize that you forgot to &lt;FONT face="courier new,courier"&gt;close()&lt;/FONT&gt; several objects. Please try with the fixes commented " &lt;FONT face="courier new,courier"&gt;//***TB&lt;/FONT&gt;&amp;nbsp; ":&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void test() {
    Acad::ErrorStatus es;
    AcDbObjectId objId;

    ads_name name; ads_point p;
    if (acedEntSel(_T("\nSelect block reference: "), name, p) != RTNORM)
        return;

    acdbGetObjectId(objId, name);
    AcDbBlockReference* pBlkRef;
    es = acdbOpenObject(pBlkRef, objId, AcDb::kForRead, false);
    if (es != Acad::eOk) 
		return;
	pBlkRef-&amp;gt;close();	// ***TB Don't forget to close pBlkRef!!!

    AcDbDynBlockReference dynBlk(objId);
    AcDbBlockTableRecordPointer pBTR(dynBlk.dynamicBlockTableRecord(), AcDb::kForRead);
    if (pBTR.openStatus() != Acad::eOk) 
		return;

    // Open Dictionary of Block Table Record
    objId = pBTR-&amp;gt;extensionDictionary();
    AcDbDictionary* pDic;
    es = acdbOpenObject(pDic, objId, AcDb::kForRead, false); //  ***TB (kForRead is enough)
    if (es != Acad::eOk) 
		return;

    // Open EvalGraph
    es = pDic-&amp;gt;getAt(_T("ACAD_ENHANCEDBLOCK"), objId);
	pDic-&amp;gt;close();			// ***TB Don't forget to close pDic!!!
    if (es != Acad::eOk) 
		return;

    AcDbEvalGraph* graph;
    es = acdbOpenObject(graph, objId, AcDb::kForRead, false);  //  ***TB (kForRead is enough)
    if (es != Acad::eOk) 
		return;

    // Get length of NodeIdArray
    AcDbEvalNodeIdArray nodes;
    es = graph-&amp;gt;getAllNodes(nodes);
	graph-&amp;gt;close();			// ***TB Don't forget to close graph!!!
	
    if (es != Acad::eOk) 
		return;
    acutPrintf(_T("\nLength: %d"), nodes.length()); // ***TB braces fixed
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using smart pointers avoid the danger to forget to close open objects. They automatically close the object as soon as they go out of scope. Instead of writing&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;es = acdbOpenObject(pBlkRef, objId, AcDb::kForRead, false);&lt;/LI-CODE&gt;
&lt;P&gt;you can write&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;AcDbObjectPointer&amp;lt;AcDbBlockReference&amp;gt; pBlkRef(objId, AcDb::kForRead, false); 
es = pBlkRef.openStatus();&lt;/LI-CODE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;AcDbObjectPointer&amp;lt;T&amp;gt;&lt;/FONT&gt; have an overloaded &lt;FONT face="courier new,courier"&gt;operator-&amp;gt;()&lt;/FONT&gt; so that you can use it exactly like a normal pointer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 07:31:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-use-acdbevalgraph-getallnodes/m-p/12208813#M1502</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2023-08-31T07:31:28Z</dc:date>
    </item>
  </channel>
</rss>

