I did not deep testing, but you can try this code:
[code]
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(Rivilis.EvalLisp))]
namespace Rivilis
{
public class EvalLisp
{
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint="?acedEvaluateLisp@@YAHPBDAAPAUresbuf@@@Z") ]
// For AutoCAD 2007: CharSet = CharSet.Unicode
// [DllImport("acad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl
// EntryPoint="?acedEvaluateLisp@@YAHPB_WAAPAUresbuf@@@Z") ]
extern static int acedEvaluateLisp(string arg, out IntPtr result);
//-----------------------------------------------------------------
// AcadEvalLisp
// ---------------
// Function evaluate lisp-expression passed as string
// arg - lisp-expression
// Return: ResultBuffer
//-----------------------------------------------------------------
static public ResultBuffer AcadEvalLisp(string arg)
{
IntPtr rb = IntPtr.Zero;
acedEvaluateLisp(arg, out rb);
if (rb != IntPtr.Zero)
{
try
{
ResultBuffer rbb = DisposableWrapper.Create(typeof(ResultBuffer), rb, true) as ResultBuffer;
return rbb;
}
catch
{
return null;
}
}
return null;
}
//-----------------------------------------------------------------
//
// Only for testing
//
//-----------------------------------------------------------------
[CommandMethod("TestEval")]
static public void TestEval()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptStringOptions pr = new PromptStringOptions("\nType Lisp-expression: ");
pr.AllowSpaces = true;
PromptResult res = ed.GetString(pr);
if (res.Status == PromptStatus.OK)
{
ResultBuffer args = AcadEvalLisp(res.StringResult);
if (args != null)
{
StringBuilder s = new StringBuilder();
s.Append("\n-----------------------------");
try
{
foreach (TypedValue val in (IEnumerable) args)
{
s.AppendFormat("\n{0} -> {1}", val.TypeCode, val.Value.ToString());
}
}
catch
{
}
s.Append("\n-----------------------------");
ed.WriteMessage(s.ToString());
}
else
{
ed.WriteMessage("\nNo return! :(");
}
}
}
}
}
[/code]