I found a sample of code on these forums that takes an object passed to the function via lisp and modifies it. I stripped it down some in order to just test that the function loads properly, and it does not seem to.
Imports Autodesk Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Colors Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports System.Windows.Forms Imports Autodesk.AutoCAD.EditorInput Namespace LispFunctionTest Public Class Class1 <LispFunction("msgtext")> _ Public Sub msgtest(ByVal resbuf As ResultBuffer) Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim ed As Editor = doc.Editor Dim db As Database = doc.Database If resbuf Is Nothing Then ed.WriteMessage(vbLf & "Error: too few arguments" & vbLf) Return End If Dim args As TypedValue() = resbuf.AsArray() If args.Length = 0 Then ed.WriteMessage(vbLf & "Error: too few arguments" & vbLf) Return End If If args.Length > 1 Then ed.WriteMessage(vbLf & "Error: too much arguments" & vbLf) Return End If If args(0).TypeCode <> LispDataType.Text Then ed.WriteMessage(vbLf & "Error: incorrect argument" & vbLf) Return End If End Sub End Class End Namespace
It gives me the following error:
System.ArgumentException: Error binding to target method.
at System.Delegate.CreateDelegate(Type type, Object firstArgument,
MethodInfo method, Boolean throwOnBindFailure)
at System.Delegate.CreateDelegate(Type type, Object firstArgument,
MethodInfo method)
at AcMgCommandClass.InvokeWorker(AcMgCommandClass* , MethodInfo mi, Object
commandObject, Boolean bLispFunction)
at AcMgCommandClass.InvokeWorkerWithExceptionFilter(AcMgCommandClass* ,
MethodInfo mi, Object commandObject, Boolean bLispFunction)
at AcMgPerDocumentCommandClass.Invoke(AcMgPerDocumentCommandClass* ,
gcroot<System::Reflection::MethodInfo ^>* mi, Boolean bLispFunction)
at AcMgCommandClass.CommandThunk.InvokeLisp(CommandThunk* )*Cancel*
Any help would be much appreciated.
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Solved by dan.glassman. Go to Solution.
Works here with AutoCAD 2011 SP1.
I could be remembering incorrectly, but I think other versions may have required a function returning an object, i.e.
Public Function msgtest(ByVal resbuf As ResultBuffer) As Object
Does it change if you do that (and return Nothing?)
-drg