<?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: LispFunction in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225586#M7465</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why instantiate the overhead of a Transaction to test for the correct entity type?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wouldn't it be more efficient to instead simply test the ObjectId for&amp;nbsp;co.ObjectClass.Name first, if it passes, then use the Transaction?&lt;/P&gt;</description>
    <pubDate>Thu, 07 Sep 2023 19:02:17 GMT</pubDate>
    <dc:creator>BlackBox_</dc:creator>
    <dc:date>2023-09-07T19:02:17Z</dc:date>
    <item>
      <title>LispFunction</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12218955#M7460</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I have a problem with passing a polyline to C# .Net.&lt;/P&gt;&lt;P&gt;I wrote .Net codes to get an object from Lisp and then calculating Area and also get bounding box of the object, but Autocad crashs after selecting a closed polyline. (I will appreciate anyone who corrects codes and adding bounding box method to it)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(setq ent (car (entsel)))
(mylispfunc ent)&lt;/LI-CODE&gt;&lt;LI-CODE lang="general"&gt; [LispFunction("MyLispFunc")]
        public ResultBuffer mylispfunc(ResultBuffer resBuf)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            ResultBuffer rbfResult = default(ResultBuffer);
            var args = resBuf.AsArray();
            ObjectId co = (ObjectId)((TypedValue)(args.GetValue(0))).Value;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Polyline lwp = tr.GetObject(co, OpenMode.ForRead) as Polyline;
                double arr = lwp.Area;
                tr.Commit();
            }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 13:55:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12218955#M7460</guid>
      <dc:creator>bahman.jf.68</dc:creator>
      <dc:date>2023-09-05T13:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12220748#M7461</link>
      <description>&lt;P&gt;Have you tried stepping through your code in the debugger to find out what is going on?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, crash is a vague description. What exactly does AutoCAD do? Does it show an error of some kind? Let this not be a guessing game.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 03:47:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12220748#M7461</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2023-09-06T03:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225444#M7462</link>
      <description>&lt;P&gt;Yes, the error is to this line :&lt;/P&gt;&lt;PRE&gt;  double arr = lwp.Area;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2023 17:48:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225444#M7462</guid>
      <dc:creator>bahman.jf.68</dc:creator>
      <dc:date>2023-09-07T17:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225514#M7463</link>
      <description>&lt;P&gt;Since you have this line of code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="lia-code-sample line-numbers language-general" tabindex="0"&gt;&lt;CODE&gt;Polyline lwp = tr.GetObject(co, OpenMode.ForRead) as Polyline;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if the opened DBObject by the Transaction is not a Polyline, the variable "lwp" would be points to null, thus the next line will raise error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should test like this:&lt;/P&gt;
&lt;P&gt;Polyline lwp=tr.GetObject(co, OpenMode.ForRead) as Polyline;&lt;/P&gt;
&lt;P&gt;if (lwp != null)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; double arr = lwp.Area;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;else&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;// you may want to raise/throw an invalid argumentException to indicate the selected entity is not a Polyline, for the&amp;nbsp; &amp;nbsp; calling lisp code to handle.&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 18:21:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225514#M7463</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2023-09-07T18:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225583#M7464</link>
      <description>&lt;P&gt;You do not mention what specific error it is. If as suggested by another reply the object is not a polyline then it will be a null reference exception. If the object is a polyline then it could be something else.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My standard advice on polyline area has always been to use COM to get the area because the managed Curve.Area property can produce incorrect results with closed, self-intersecting polylines.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 18:56:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225583#M7464</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2023-09-07T18:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225586#M7465</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why instantiate the overhead of a Transaction to test for the correct entity type?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wouldn't it be more efficient to instead simply test the ObjectId for&amp;nbsp;co.ObjectClass.Name first, if it passes, then use the Transaction?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 19:02:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225586#M7465</guid>
      <dc:creator>BlackBox_</dc:creator>
      <dc:date>2023-09-07T19:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225634#M7466</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1206685"&gt;@BlackBox_&lt;/a&gt;&amp;nbsp;: I simply pointed out the direct reason of the error OP gets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the LISP function does required Polyline, not other curves (Arc, Circle...) as input, then I am with you: I'd first test ObjectId.ObjectClass.Name/ObjectId.ObjectClass.DxfName to make sure it is Polyline before starting a Transaction&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 19:20:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225634#M7466</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2023-09-07T19:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction</title>
      <link>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225761#M7467</link>
      <description>&lt;P&gt;Thank you everyone for replying.&lt;/P&gt;&lt;P&gt;The problem resolved with this line :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (lwp != null)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; double arr = lwp.Area;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&amp;nbsp;Thanks for your advice, I dont have more exprience with COM programming, I'm good at AutoLisp and I have been working with C# Pure .Net for about one year. Also I think Pure .Net is so quicker than Com or Lisp.&lt;/P&gt;&lt;P&gt;But regarding intersection errors, I think all Lisp, vba, C# returns incorrect result.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 20:54:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/lispfunction/m-p/12225761#M7467</guid>
      <dc:creator>bahman.jf.68</dc:creator>
      <dc:date>2023-09-07T20:54:02Z</dc:date>
    </item>
  </channel>
</rss>

