Just to add to that, a return type of ResultBuffer results
in a LIST being returned to LISP with the contennts of the
ResultBuffer. To return an atom, you can just declare the
function with the LispFunction attribute to return any type
that can go in a result buffer.
So for example, your ConcatStrings function should return
a string, not a ResultBuffer:
[code]
[LispFunction("ConcatStrings")]
static public string ConcatStrings(ResultBuffer args)
{
StringBuilder sb = new StringBuilder();
foreach (TypedValue rb in args)
{
if( rb.Value is string )
sb.Append((string) rb.Value);
}
return sb.ToString();
}
[/code]
One other thing, is that when you iteratively concatenate
strings in .NET, it is much more efficient to use StringBulider
instead of using += on a string.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
wrote in message news:5162318@discussion.autodesk.com...
Ok! 🙂
It is a simple example of function PrintArgs which print all it's parameters and return it back to lisp:
[code]
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
namespace ClassLibrary
{
public class Class
{
//
// From adscodes.h :
//
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 */
[LispFunction("PrintArgs")]
static public ResultBuffer PrintArgs(ResultBuffer args)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
foreach (TypedValue rb in args) {
switch (rb.TypeCode) {
case RTLB:
ed.WriteMessage("(");
break;
case RTLE:
ed.WriteMessage(")");
break;
case RTSTR:
ed.WriteMessage("\"{0}\"",rb.Value);
break;
case RTT:
ed.WriteMessage(" T ");
break;
case RTNIL:
ed.WriteMessage(" nil ");
break;
default:
ed.WriteMessage(" {0} ", rb.Value);
break;
}
}
return args;
}
}
}
[/code]
Test:
Command: (printargs '("String" (1.0 2.0) (1.0 2.0 3.0) T nil 100 200.5))
("String" (1,2) (1,2,3) T nil 100 200,5 )("String" (1.0 2.0) (1.0 2.0 3.0)
T nil 100 200.5)
Another example, such as (strcat ...) function:
[code]
[LispFunction("ConcatStrings")]
static public ResultBuffer ConcatStrings(ResultBuffer args)
{
ResultBuffer resbuf = new ResultBuffer();
String s = "";
foreach (TypedValue rb in args)
{
if (rb.TypeCode == RTSTR)
{
s += rb.Value;
}
}
resbuf.Add(new TypedValue(RTSTR, s));
return resbuf;
}
[/code]
Test:
Command: (concatstrings "Hello" ", " "World" "!") ("Hello, World!")