AutoCAD二次开发(.Net)之读写LSP变量

xiaoxiao2021-02-28  44

//LSP变量的写入 [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("accore.dll", EntryPoint = "acedPutSym",CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] extern static private int acedPutSym(string args, IntPtr result); //32位的CAD的动态链接库和64位的有分别,下面是32位的方法 [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("accore.dll", EntryPoint = "_acedPutSym",CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] extern static private int acedPutSym32(string args, IntPtr result); /// <summary> /// Set a LISP variable value. /// </summary> /// <param name="name">The variable name.</param> /// <param name="rb">The variable value</param> public static void SetLispSym(string name, ResultBuffer rb) { if (Environment.Is64BitOperatingSystem)//判断系统是32位还是64位 { acedPutSym(name, rb.UnmanagedObject); } else { acedPutSym32(name, rb.UnmanagedObject); } } //LSP变量的读取 [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("accore.dll", EntryPoint = "acedGetSym",CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] extern static private int acedGetSym(string args, out IntPtr result); [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("accore.dll", EntryPoint = "_acedGetSym",CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] extern static private int acedGetSym32(string args, out IntPtr result); /// <summary> /// Get a LISP variable value. /// </summary> /// <param name="name">The variable name.</param> /// <returns>The variable value or null if failed.</returns> public static ResultBuffer GetLispSym(string name) { IntPtr ip = IntPtr.Zero; if (Environment.Is64BitOperatingSystem) { int status = acedGetSym(name, out ip); if (status == (int)PromptStatus.OK && ip != IntPtr.Zero) { return ResultBuffer.Create(ip, true); } } else { int status = acedGetSym32(name, out ip); if (status == (int)PromptStatus.OK && ip != IntPtr.Zero) { return ResultBuffer.Create(ip, true); } } return null; } /// <summary>         /// LSP变量赋值         /// </summary>         /// <param name="volLevel"></param>         private static void SetLSPVar(string varName, string volLevel)         {             Autodesk.AutoCAD.DatabaseServices.ResultBuffer rb = new Autodesk.AutoCAD.DatabaseServices.ResultBuffer();             rb.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(5005, volLevel));             CADHelperClass.SetLispSym(varName, rb);         } //读取LSP变量 private static string ReadLSPVar(string varName)         {             string name = "";             ResultBuffer rb = GetLispSym(varName);             foreach (TypedValue val in (System.Collections.IEnumerable)rb)             {                 name = val.Value.ToString();             }             return name;         }

 

 

 

转载请注明原文地址: https://www.6miu.com/read-2627695.html

最新回复(0)