using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using System.Runtime.InteropServices;
namespace ClassLibrary2
{
public class Class1
{
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
extern static private int acedInvoke(IntPtr args, out IntPtr result);
public static ResultBuffer CallLispFunction(ResultBuffer args)
{
IntPtr ip = IntPtr.Zero;
int st = acedInvoke(args.UnmanagedObject, out ip);
if (ip != IntPtr.Zero)
{
ResultBuffer rbRes = ResultBuffer.Create(ip, true);
return rbRes;
}
return null;
}
private static void AddValueToResultBuffer(ref ResultBuffer rb, object obj)
{
if (obj == null)
{
rb.Add(new TypedValue((int)LispDataType.Text, ""));
}
else
{
if (obj is string)
{
rb.Add(new TypedValue((int)LispDataType.Text, obj));
}
else if (obj is Point2d)
{
rb.Add(new TypedValue((int)LispDataType.Text, "_non"));
rb.Add(new TypedValue((int)LispDataType.Point2d, obj));
}
else if (obj is Point3d)
{
rb.Add(new TypedValue((int)LispDataType.Text, "_non"));
rb.Add(new TypedValue((int)LispDataType.Point3d, obj));
}
else if (obj is ObjectId)
{
rb.Add(new TypedValue((int)LispDataType.ObjectId, obj));
}
else if (obj is SelectionSet)
{
rb.Add(new TypedValue((int)LispDataType.SelectionSet, obj));
}
else if (obj is double)
{
rb.Add(new TypedValue((int)LispDataType.Double, obj));
}
else if (obj is short)
{
rb.Add(new TypedValue((int)LispDataType.Int16, obj));
}
else if (obj is int)
{
rb.Add(new TypedValue((int)LispDataType.Int32, obj));
}
else if (obj is TypedValue)
{
rb.Add(obj);
}
}
}
public static ResultBuffer CallLispFunction(string name, params object[] args)
{
ResultBuffer rbArgs = new ResultBuffer();
rbArgs.Add(new TypedValue((int)LispDataType.Text, name));
foreach (object val in args)
{
AddValueToResultBuffer(ref rbArgs, val);
}
return CallLispFunction(rbArgs);
}
[LispFunction("GetArr")]
public static ResultBuffer GetArr(ResultBuffer resBufIn)
{
ResultBuffer resBufOut = new ResultBuffer();
resBufOut.Add(new TypedValue((int)LispDataType.ListBegin));
resBufOut.Add(
new TypedValue((int)LispDataType.Int16, 700));
resBufOut.Add(
new TypedValue((int)LispDataType.Int16, 800));
resBufOut.Add(
new TypedValue((int)LispDataType.Int16, 18));
resBufOut.Add(
new TypedValue((int)LispDataType.Text, "a+b"));
resBufOut.Add(new TypedValue((int)LispDataType.ListEnd));
resBufOut.Add(new TypedValue((int)LispDataType.ListBegin));
resBufOut.Add(
new TypedValue((int)LispDataType.Int16, 700));
resBufOut.Add(
new TypedValue((int)LispDataType.Int16, 800));
resBufOut.Add(
new TypedValue((int)LispDataType.Int16, 18));
resBufOut.Add(
new TypedValue((int)LispDataType.Text, "a+b"));
resBufOut.Add(new TypedValue((int)LispDataType.ListEnd));
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("test");
return resBufOut;
}
[LispFunction("tt")]
public static ResultBuffer tt(ResultBuffer resBufIn)
{
ResultBuffer resBufOut = new ResultBuffer();
resBufOut = CallLispFunction("getarr");
resBufOut.Add(
new TypedValue((int)LispDataType.Int16, 700));
return resBufOut;
//return resBufOut;
}
}
}