newer 发表于 2021-1-16 21:11:37

使用 acedInvoke 调用 LISP函数

Calling Lisp function using acedInvoke

问题:

I am using acedInvoke to call a Lisp function but I get a return value that equals RTERROR (5001). What am I missing ?

解答:

The Lisp function must be defined as a command as shown here :


;;; (defun DoIt() Define the Lisp function as a command using c:

(defun c:DoIt()

(setq pntA (getpoint "\nPick A")

      pntB (getpoint pntA "\nPick B")

)

(grdraw pntA pntB 1 2)

)



Here is the sample code to call the Lisp command using acedInvoke :

<DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedInvoke")> _

Private Shared Function acedInvoke(ByVal args As IntPtr, ByRef result As IntPtr) As Integer

End Function



. . .



Dim m_args As New Autodesk.AutoCAD.DatabaseServices.ResultBuffer()



'Returns RTERROR (5001)

'm_args.Add(New Autodesk.AutoCAD.DatabaseServices.TypedValue(5005, "DoIt"))



'Returns RTNORM (5100)

m_args.Add(New Autodesk.AutoCAD.DatabaseServices.TypedValue(5005, "c:DoIt"))



Dim m_ResultBuf As IntPtr = IntPtr.Zero

Dim m_Return As Integer = acedInvoke(m_args.UnmanagedObject, m_ResultBuf)



m_args.Dispose()

MsgBox(String.Format("Return value {0}", m_Return))


页: [1]
查看完整版本: 使用 acedInvoke 调用 LISP函数