Hi,
The main difficulty when trying to play with AutoLISP and C# is that the first is dynamicly (not) typed and the second is strongly and staticly typed.
With AutoLISP, a list of 2 or 3 (real or integer) numbers can be used as a point or a vector. The interpretor can convert this list into a list of 3 real numbers (double) to use it as a Point3d. (0 0), (0 0 0), (0.0 0.0), (0.0 0.0 0.0) can be interpreted the same.
The AutoCAD .NET API has a specific Point2d, Point3d, Vector2d and Vector3d types.
AutoLISP can also interpret a list of 3 or 4 numbers as a DXF data when the first one is an integer which corresponds to a valid DXF group code, e.g.: (10 0.0 0.0 0.0) which .NET corresponding value is: TypedValue(10, Point3d.Origin).
That said, those who implemented the .NET LispFunction API thaught it should be a good thing to implicitly convert some type of list of numbers passed as argument to the LispFunction method into specific TypedValue instances as Point2d, Point3d, DXF list...or worst, throw an error in case of "invalid DXF list".
IMO they should have let the end user (developer) decide how to convert a list of numbers.
You can do some tests with the following function:
[LispFunction("TestType")]
public static object TestType(ResultBuffer resBufIn)
{
var ed = Application.DocumentManager.MdiActiveDocument.Editor;
try
{
if (resBufIn != null)
{
TypedValue[] tvArr = resBufIn.AsArray();
foreach (var tv in tvArr)
{
ed.WriteMessage($"TypeCode: {(LispDataType)tv.TypeCode}\tValue: {tv.Value}\n");
}
}
}
catch(System.Exception ex)
{
ed.WriteMessage($"{ex.Message}\n");
}
// return the resBufIn to see how it have been converted on the .NET side
return resBufIn;
}
Some results:
Command: (testType '(0 0))
TypeCode: Point2d Value: (0,0)
((0.0 0.0))
Command: (testType '(0 0 0))
TypeCode: Point3d Value: (0,0,0)
((0.0 0.0 0.0))
Command: (testType '(10 10 10))
TypeCode: 10 Value: (10,10,0)
((10 10.0 10.0 0.0))
Command: (testType '(10.0 10 10))
TypeCode: Point3d Value: (10,10,10)
((10.0 10.0 10.0))
Command: (testType '(19 10 10))
eInvalidResBuf
((19 10.0 10.0 0.0))
Command: (testType '(10 10 10 10))
TypeCode: 10 Value: (10,10,10)
((10 10.0 10.0 10.0))
Command: (testType '(10.0 10 10 10))
TypeCode: ListBegin Value: -1
TypeCode: Double Value: 10
TypeCode: Int16 Value: 10
TypeCode: Int16 Value: 10
TypeCode: Int16 Value: 10
TypeCode: ListEnd Value: -1
(10.0 10 10 10)
As you can see, the only way to ensure the 3 numbers list argument is interpreted as a Point3d is to explicitly write real numbers (at least the first one) on the LISP side (which not an habit with a dynamic typed language).