<?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 : Problem Calling a LISP routine from C# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/problem-calling-a-lisp-routine-from-c/m-p/6023503#M37227</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems to me you cannot call commands from a LISP which is invoked from .NET (just writing this sentence shows how this process seems complex for such a simple stuff).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not directly call the commands from .NET (using Document.SendStringtoExecute() or Editor.Command() methods) ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, better, add these layers (LayerTableRecord objects) to the LayerTable using &lt;A href="http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-7BF88244-D866-40D1-8C21-7DD1A2C633DF" target="_blank"&gt;the .NET API&lt;/A&gt;. This may be a good learning exercise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most of the time, calling LISP from .NET is definitely not a simple task and there are many issues you'll be facing due to the differences between the two environments (document context vs application context, interpreted language vs compiled language, dynamic types vs static types, ...)&lt;/P&gt;</description>
    <pubDate>Thu, 04 Feb 2016 08:11:45 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2016-02-04T08:11:45Z</dc:date>
    <item>
      <title>Problem Calling a LISP routine from C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-calling-a-lisp-routine-from-c/m-p/6023176#M37226</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I'm trying to setup layers using previously written LISP code in my C# program. My LISP code is:&lt;/P&gt;&lt;P&gt;(defun c:SetUpLayers ()&lt;BR /&gt;&amp;nbsp; (command "-layer" "m" "const1" "c" "1")&lt;BR /&gt;&amp;nbsp; (command "")&lt;BR /&gt;&amp;nbsp; (command "")&lt;BR /&gt;&amp;nbsp; (command "-layer" "m" "const2" "c" "5")&lt;BR /&gt;&amp;nbsp; (command "")&lt;BR /&gt;&amp;nbsp; (command "")&lt;BR /&gt;&amp;nbsp; (command "-layer" "m" "const3" "c" "3")&lt;BR /&gt;&amp;nbsp; (command "")&lt;BR /&gt;&amp;nbsp; (command "")&lt;BR /&gt;) ;ends and sets all layers for sloper building&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am calling this function from C# with this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;[CommandMethod("SetUpLayers", CommandFlags.Modal)]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void SetUpLayers() //Setup AutoCad drawing Layers&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // build the arguments list&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ResultBuffer args = new ResultBuffer(&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new TypedValue((int)LispDataType.Text, "c:SetUpLayers"));&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // call the LISP fuction anf get the return value&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ResultBuffer result = Autodesk.AutoCAD.ApplicationServices.Application.Invoke(args);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ed.WriteMessage(result.ToString());&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;Although this code ran perfectly when I invoked it in a LISP program, I am getting this error when I try and run it from C#&lt;/P&gt;&lt;P&gt;; error: AutoCAD command rejected: "-layer"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me out?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~Vonnie&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2016 01:40:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-calling-a-lisp-routine-from-c/m-p/6023176#M37226</guid>
      <dc:creator>ganderson</dc:creator>
      <dc:date>2016-02-04T01:40:00Z</dc:date>
    </item>
    <item>
      <title>Re : Problem Calling a LISP routine from C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-calling-a-lisp-routine-from-c/m-p/6023503#M37227</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems to me you cannot call commands from a LISP which is invoked from .NET (just writing this sentence shows how this process seems complex for such a simple stuff).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not directly call the commands from .NET (using Document.SendStringtoExecute() or Editor.Command() methods) ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, better, add these layers (LayerTableRecord objects) to the LayerTable using &lt;A href="http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-7BF88244-D866-40D1-8C21-7DD1A2C633DF" target="_blank"&gt;the .NET API&lt;/A&gt;. This may be a good learning exercise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most of the time, calling LISP from .NET is definitely not a simple task and there are many issues you'll be facing due to the differences between the two environments (document context vs application context, interpreted language vs compiled language, dynamic types vs static types, ...)&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2016 08:11:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-calling-a-lisp-routine-from-c/m-p/6023503#M37227</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-02-04T08:11:45Z</dc:date>
    </item>
    <item>
      <title>Re : Problem Calling a LISP routine from C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-calling-a-lisp-routine-from-c/m-p/6024849#M37228</link>
      <description>&lt;P&gt;Thanks for your help. I have a program that I wrote years ago that I'd like to interact with the C# program that I am working on now. Up til now, all the LISP calls that I've made from C# have worked flawlessly, but I will take your advice and use the .NET API for working with Layers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~Giovonnae&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2016 19:50:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-calling-a-lisp-routine-from-c/m-p/6024849#M37228</guid>
      <dc:creator>ganderson</dc:creator>
      <dc:date>2016-02-04T19:50:01Z</dc:date>
    </item>
  </channel>
</rss>

