.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create Lisp function with arguments in .net

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
docsaintly
2216 Views, 3 Replies

Create Lisp function with arguments in .net

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.

3 REPLIES 3
Message 2 of 4
dan.glassman
in reply to: docsaintly

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

Message 3 of 4
_gile
in reply to: dan.glassman

Hi,

 

A LISP function may always return something even nil: new TypedValue(LispDataType.Nil).

It seems that A2008 requires the return to be a ResultBuffer, other versions (2007, 2009, 2010, 2011) accept any type of object.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4
docsaintly
in reply to: docsaintly

Worked like a charm returning nothing. Thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost