Message 1 of 6
acedGetSym and acedPutSym in .NET applications
Not applicable
05-05-2006
12:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, All!
I've wrote a class, which can be helpful in .NET for getting/puttings value of lisp-variables:
[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.AcadLispSym))]
namespace Rivilis
{
public class AcadLispSym
{
//
// From adscodes.h :
//
// Type of resbuf element
const int RTNONE = 5000; /* No result */
const int RTREAL = 5001; /* Real number */
const int RTPOINT = 5002; /* 2D point X and Y only */
const int RTSHORT = 5003; /* Short integer */
const int RTANG = 5004; /* Angle */
const int RTSTR = 5005; /* String */
const int RTENAME = 5006; /* Entity name */
const int RTPICKS = 5007; /* Pick set */
const int RTORINT = 5008; /* Orientation */
const int RT3DPOINT = 5009; /* 3D point - X, Y, and Z */
const int RTLONG = 5010; /* Long integer */
const int RTVOID = 5014; /* Blank symbol */
const int RTLB = 5016; /* list begin */
const int RTLE = 5017; /* list end */
const int RTDOTE = 5018; /* dotted pair */
const int RTNIL = 5019; /* nil */
const int RTDXF0 = 5020; /* DXF code 0 for ads_buildlist only */
const int RTT = 5021; /* T atom */
const int RTRESBUF = 5023; /* resbuf */
const int RTMODELESS = 5027; /* interrupted by modeless dialog */
// Error return code
const int RTNORM = 5100; /* Request succeeded */
const int RTERROR = -5001; // Some other error
const int RTCAN = -5002; // User cancelled request -- Ctl-C
const int RTREJ = -5003; // AutoCAD rejected request -- invalid
const int RTFAIL = -5004; // Link failure -- Lisp probably died
const int RTKWORD = -5005; // Keyword returned from getxxx() routine
const int RTINPUTTRUNCATED = -5008; // Input didn't all fit in the buffer
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
// For AutoCAD 2007: CharSet = CharSet.Unicode
// [DllImport("acad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
extern static private int acedGetSym(string args, out IntPtr result);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
// For AutoCAD 2007: CharSet = CharSet.Unicode
// [DllImport("acad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
extern static private int acedPutSym(string args, IntPtr result);
//-----------------------------------------------------------------
// AcadGetSym
// --------------
// Fuction get value of lisp-variable
// varname - name of variable
// stat - return code
// Return: ResultBuffer
//-----------------------------------------------------------------
static public ResultBuffer AcadGetSym(string varname,ref int stat)
{
IntPtr rb = IntPtr.Zero;
stat = acedGetSym(varname, out rb);
if (stat == (int)PromptStatus.OK && rb != IntPtr.Zero)
return (ResultBuffer) DisposableWrapper.Create(typeof(ResultBuffer), rb, true);
return null;
}
//-----------------------------------------------------------------
// AcadPutSym
// --------------
// Function put new value to lisp-variable
// varname - name of variable
// rb - ResultBufer
// Return: RTNORM - if all right
//-----------------------------------------------------------------
static public int AcadPutSym(string varname, ResultBuffer rb)
{
return acedPutSym(varname, rb.UnmanagedObject);
}
//
// Test command for geting value of lisp-variable and print it value
//
[CommandMethod("GetSym")]
static public void GetSym()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
int stat = 0;
PromptResult res = ed.GetString("\nName of lisp-variable: ");
if (res.Status == PromptStatus.OK)
{
ResultBuffer args = AcadGetSym(res.StringResult,ref stat) ;
if (args != null)
{
StringBuilder s = new StringBuilder();
s.Append("\n-----------------------------");
foreach (TypedValue val in (IEnumerable) args)
{
s.AppendFormat("\n{0} -> {1}", val.TypeCode, val.Value.ToString());
}
s.Append("\n-----------------------------");
ed.WriteMessage(s.ToString());
}
}
}
//
// Test command for setting value of lisp-variable
//
[CommandMethod("PutSym")]
static public void PutSym()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptResult res = ed.GetString("\nName of lisp-variable: ");
if (res.Status == PromptStatus.OK)
{
ResultBuffer args = new ResultBuffer();
//
// If I add RTLB and RTLE in AutoCAD 2007 - all right, in AutoCAD 2006
// value of lisp-varible is nil
//
// args.Add(new TypedValue(RTLB,-1));
args.Add(new TypedValue(RTSTR,"New String"));
// args.Add(new TypedValue(RTLE,-1));
AcadPutSym(res.StringResult,args) ;
}
}
}
}
[/code]
My question is:
Why in AutoCAD 2006 I can not get/put lisp-variables which is list of atoms (e.g. (= (type var) 'LIST)?
In AutoCAD 2007 I have not problem with this kind of variables.
I've wrote a class, which can be helpful in .NET for getting/puttings value of lisp-variables:
[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.AcadLispSym))]
namespace Rivilis
{
public class AcadLispSym
{
//
// From adscodes.h :
//
// Type of resbuf element
const int RTNONE = 5000; /* No result */
const int RTREAL = 5001; /* Real number */
const int RTPOINT = 5002; /* 2D point X and Y only */
const int RTSHORT = 5003; /* Short integer */
const int RTANG = 5004; /* Angle */
const int RTSTR = 5005; /* String */
const int RTENAME = 5006; /* Entity name */
const int RTPICKS = 5007; /* Pick set */
const int RTORINT = 5008; /* Orientation */
const int RT3DPOINT = 5009; /* 3D point - X, Y, and Z */
const int RTLONG = 5010; /* Long integer */
const int RTVOID = 5014; /* Blank symbol */
const int RTLB = 5016; /* list begin */
const int RTLE = 5017; /* list end */
const int RTDOTE = 5018; /* dotted pair */
const int RTNIL = 5019; /* nil */
const int RTDXF0 = 5020; /* DXF code 0 for ads_buildlist only */
const int RTT = 5021; /* T atom */
const int RTRESBUF = 5023; /* resbuf */
const int RTMODELESS = 5027; /* interrupted by modeless dialog */
// Error return code
const int RTNORM = 5100; /* Request succeeded */
const int RTERROR = -5001; // Some other error
const int RTCAN = -5002; // User cancelled request -- Ctl-C
const int RTREJ = -5003; // AutoCAD rejected request -- invalid
const int RTFAIL = -5004; // Link failure -- Lisp probably died
const int RTKWORD = -5005; // Keyword returned from getxxx() routine
const int RTINPUTTRUNCATED = -5008; // Input didn't all fit in the buffer
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
// For AutoCAD 2007: CharSet = CharSet.Unicode
// [DllImport("acad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
extern static private int acedGetSym(string args, out IntPtr result);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
// For AutoCAD 2007: CharSet = CharSet.Unicode
// [DllImport("acad.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
extern static private int acedPutSym(string args, IntPtr result);
//-----------------------------------------------------------------
// AcadGetSym
// --------------
// Fuction get value of lisp-variable
// varname - name of variable
// stat - return code
// Return: ResultBuffer
//-----------------------------------------------------------------
static public ResultBuffer AcadGetSym(string varname,ref int stat)
{
IntPtr rb = IntPtr.Zero;
stat = acedGetSym(varname, out rb);
if (stat == (int)PromptStatus.OK && rb != IntPtr.Zero)
return (ResultBuffer) DisposableWrapper.Create(typeof(ResultBuffer), rb, true);
return null;
}
//-----------------------------------------------------------------
// AcadPutSym
// --------------
// Function put new value to lisp-variable
// varname - name of variable
// rb - ResultBufer
// Return: RTNORM - if all right
//-----------------------------------------------------------------
static public int AcadPutSym(string varname, ResultBuffer rb)
{
return acedPutSym(varname, rb.UnmanagedObject);
}
//
// Test command for geting value of lisp-variable and print it value
//
[CommandMethod("GetSym")]
static public void GetSym()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
int stat = 0;
PromptResult res = ed.GetString("\nName of lisp-variable: ");
if (res.Status == PromptStatus.OK)
{
ResultBuffer args = AcadGetSym(res.StringResult,ref stat) ;
if (args != null)
{
StringBuilder s = new StringBuilder();
s.Append("\n-----------------------------");
foreach (TypedValue val in (IEnumerable) args)
{
s.AppendFormat("\n{0} -> {1}", val.TypeCode, val.Value.ToString());
}
s.Append("\n-----------------------------");
ed.WriteMessage(s.ToString());
}
}
}
//
// Test command for setting value of lisp-variable
//
[CommandMethod("PutSym")]
static public void PutSym()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptResult res = ed.GetString("\nName of lisp-variable: ");
if (res.Status == PromptStatus.OK)
{
ResultBuffer args = new ResultBuffer();
//
// If I add RTLB and RTLE in AutoCAD 2007 - all right, in AutoCAD 2006
// value of lisp-varible is nil
//
// args.Add(new TypedValue(RTLB,-1));
args.Add(new TypedValue(RTSTR,"New String"));
// args.Add(new TypedValue(RTLE,-1));
AcadPutSym(res.StringResult,args) ;
}
}
}
}
[/code]
My question is:
Why in AutoCAD 2006 I can not get/put lisp-variables which is list of atoms (e.g. (= (type var) 'LIST)?
In AutoCAD 2007 I have not problem with this kind of variables.