Defining Methods That Can Be Called From AutoLISP
Managed applications can define methods so that they can be called by AutoLISP applications. To do so, the managed application tags the desired method with the Autodesk.AutoCAD.Runtime.LispFunction attribute. This attribute can be used in the same places and has the same properties as the CommandMethod attribute. The key difference lies in the signature form to which LispFunction may be applied. LispFunction is valid only for methods of the form
Code:
public ResultType MyHandler(ResultBuffer args) {
...
}
where ResultType can be any one of the following types:
- int
- double
- TypedValue
- ResultBuffer
- string
- Point2d
- Point3d
- bool
- void
- ObjectId
- SelectionSet
The Autodesk.AutoCAD.Runtime.LispDataType enumeration defines .NET identifiers that represent the data types passed through AutoLISP ResultBuffer arguments.
For instance, the following C# code defines an AutoLISP-callable “Hello World” method:
Code:
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
...
[LispFunction("c:helloworld")]
public void hw(ResultBuffer args)
{
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage('\n' + "Hello World!" + '\n');
}