Community
public const int RTLONG = 5010; // adscodes.h
public const int RTSTR = 5005;
public const int RTNORM = 5100;
public const int RTNIL = 5019;
public const int RTLB = 5016;
public const int RTLE = 5017;
public const int RTREAL = 5001;
public const int RTPOINT = 5002;
[CommandMethod("testinvoke")]
public static void AcedInvokeSample()
{
for (int i = 0; i < 3; i++)
{
TestInvokeLisp("c:wd_insym2", "HPB11", 0, 0, 1.0, "nil");
}
}
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
extern static private int acedInvoke(IntPtr args, out IntPtr result);
// Helper for acedInvoke()
public static ResultBuffer InvokeLisp(ResultBuffer args, ref int stat)
{
IntPtr rb = IntPtr.Zero;
stat = acedInvoke(args.UnmanagedObject, out rb);
if (stat == (int)PromptStatus.OK && rb != IntPtr.Zero)
return (ResultBuffer)
DisposableWrapper.Create(typeof(ResultBuffer), rb, true);
return null;
}
static void PrintResbuf(ResultBuffer rb)
{
string s = "\n-----------------------------";
foreach (TypedValue val in rb)
s += string.Format("\n{0} -> {1}", val.TypeCode,
val.Value.ToString());
s += "\n-----------------------------";
AcadApp.DocumentManager.MdiActiveDocument.
Editor.WriteMessage(s);
}
public static void TestInvokeLisp(string mycommand, string myblock, double mypointx, double mypointy, double myscale, string myoptions)
{
ResultBuffer args = new ResultBuffer();
int stat = 0;
string mypointnil = "nil";
args.Add(new TypedValue(RTSTR, mycommand));
args.Add(new TypedValue(RTSTR, myblock));
if (mypointx == 0 && mypointy == 0)
{
args.Add(new TypedValue(RTNIL, mypointnil));
}
else
{
args.Add(new TypedValue(RTLB, -1));
args.Add(new TypedValue(RTREAL, mypointx));
args.Add(new TypedValue(RTREAL, mypointy));
args.Add(new TypedValue(RTLE, -1));
}
args.Add(new TypedValue(RTREAL, myscale));
args.Add(new TypedValue(RTNIL, myoptions));
//args.Add(new TypedValue(RTLONG, 200));
ResultBuffer res = InvokeLisp(args, ref stat);
if (stat == RTNORM && res != null)
{
PrintResbuf(res);
res.Dispose();
}
}