When defining an AutoLISP function, you use the LispFunction attribute. The LispFunction attribute expects a string value to use as the global name of the AutoLISP function that is being defined. Along with a global function name, the LispFunction structure can accept the following values:
The following demonstrates the creation of a LispFunction attribute that defines an AutoLISP function named DisplayFullName.
[LispFunction("DisplayFullName")]
public static void DisplayFullName(ResultBuffer rbArgs)
{
. . .
}
Use a Foreach loop to step through the values returned in the ResultBuffer by the AutoLISP function. A ResultBuffer is a collection of TypedValue objects. The TypeCode property of a TypedValue object can be used to determine the value type for each value passed into the AutoLISP function. The Value property is used to return the value of the TypedValue object.
The data types supported are:
This example code defines an AutoLISP function named DisplayFullName. While the method defined in the .NET project accepts a single value, the AutoLISP function expects two string values to produce the correct output.
Load the .NET project into AutoCAD and enter the following at the Command prompt:
(displayfullname "First" "Last")
The following is the output displayed after the AutoLISP function is executed:
Name: First Last
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
[LispFunction("DisplayFullName")]
public static void DisplayFullName(ResultBuffer rbArgs)
{
if (rbArgs != null)
{
string strVal1 = "";
string strVal2 = "";
int nCnt = 0;
foreach (TypedValue rb in rbArgs)
{
if (rb.TypeCode == (int)Autodesk.AutoCAD.Runtime.LispDataType.Text)
{
switch(nCnt)
{
case 0:
strVal1 = rb.Value.ToString();
break;
case 1:
strVal2 = rb.Value.ToString();
break;
}
nCnt = nCnt + 1;
}
}
Application.DocumentManager.MdiActiveDocument.Editor.
WriteMessage("\nName: " + strVal1 + " " + strVal2);
}
}