[求助]C#编写的函数,有办法于LISP中呼叫并将运算资料进行传递吗?
请教各位高手C#编写的函数,有办法于LISP中呼叫并将运算资料进行传递吗?
烦请各位能够协助解答一下,谢谢~ 不明白楼主的问题
不过C#可以定义Lisp函数供Lisp使用,C#也可以使用Lisp函数(需要注册)
---------------------------
这里是说在较新版本的AutoCAD 谢谢解答~请问您说的部份哪边可以找到范例资料呢?是否可以提供,谢谢~ http://user.qzone.qq.com/812928665/infocenter?ptsig=VqFz*FJZppcBJ8FFEY8WcJIsdH05z0cArysBaljnHFU_ 上面连接好像有问题,
就是空间里面的日志 建议LZ先看看有关C#与Lisp语言混合编程这方面的就可以实现你的要求了 '''
''' 用.NET来运行Lisp的工具
'''
''' 1.实例化后,先LoadLisp
Public Class LispInDotNet
Private mVlFunctions As Object = Nothing
'''
''' Lisp的函数对象集
'''
'''
'''
'''
Public ReadOnly Property VlFunctions As Object
Get
Return mVlFunctions
End Get
End Property
Private mLoadSuccessful As Boolean = False
'''
''' 是否加载成功
'''
'''
'''
'''
Public ReadOnly Property LoadSuccessful As Boolean
Get
Return mLoadSuccessful
End Get
End Property
'''
''' 加载Lisp运行环境
'''
'''
'''
Public Function LoadLisp() As Boolean
'状态:20131126-1348测试通过
Try
Dim acadApp As Object = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
Dim vlApp As Object = acadApp.GetInterfaceObject("VL.Application.16") '此处出错,可能是因为没有加载VL环境所致, (vl-load-com)
'VL.Application.16 为什么会是16?到AutoCAD各版本的安装目录里到查找,会发现一个vl16.tlb,这个文件就是visual lisp的运行环境,到AutoCAD 2014为止,这个文件一直没有更新。
mVlFunctions = vlApp.ActiveDocument.Functions
mLoadSuccessful = True
Return True
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Return False
End Try
End Function
'''
''' 运行Lisp函数
'''
'''
''' 参数数组
''' 是否运行成功
''' 出错信息
'''
'''
Public Function RunLispFunction(ByVal FunctionName As String, args() As Object, Optional ByRef runSuccessful As Boolean = False, Optional ByRef ErrMsg As String = "") As Object
'状态:20131126-1711通过测试
runSuccessful = False
If Me.LoadSuccessful = True Then
If Me.HasLispFunction(FunctionName) = False Then
Return Nothing
End If
Try
Dim vlFunction As Object = mVlFunctions.Item(FunctionName)
RunLispFunction = vlFunction.GetType.InvokeMember("funcall", BindingFlags.InvokeMethod, Nothing, vlFunction, args)
runSuccessful = True
Catch ex As System.Reflection.TargetInvocationException
ErrMsg = ex.Message
Return Nothing
End Try
Else
Return Nothing
End If
End Function
'''
''' 查询当前环境是否有某个Lisp函数或者变量
'''
'''
'''
'''
Public Function HasLispFunction(ByVal functionNameOrValueName As String) As Boolean
'状态:20131126-1534通过测试
Dim vlFunction As Object = mVlFunctions.Item("read")
Dim sym As Object = vlFunction.GetType.InvokeMember("funcall", BindingFlags.InvokeMethod, Nothing, vlFunction, New Object() {functionNameOrValueName})
If sym Is Nothing Then
Return False
Else
Dim vlFuncEval As Object = mVlFunctions.Item("eval")
If vlFunction.GetType.InvokeMember("funcall", BindingFlags.InvokeMethod, Nothing, vlFuncEval, New Object() {sym}) Is Nothing Then
Return False
Else
Return True
End If
End If
End Function
'''
''' 获取Lisp变量的值
'''
'''
'''
'''
Public Function GetValue(ValueName As String) As Object
'状态:20131126-1534通过测试
Return Eval(ValueName)
End Function
'''
''' 获取一个Lisp语句的值
'''
'''
'''
'''
Public Function Eval(LispString As String) As Object
'状态:20131126-1534通过测试
Try
Dim sym As Object = RunLispFunction("read", New Object() {LispString})
If sym Is Nothing Then
Return Nothing
Else
Return RunLispFunction("eval", New Object() {sym})
End If
Catch ex As Exception
Return Nothing
End Try
End Function
'''
''' 设置Lisp变量的值
'''
''' 变量名
''' 变量值
'''
'''
Public Function SetValue(ByVal ValueName As String, ByVal Value As Object) As Boolean
'状态:20131126-1534通过测试
Dim suc As Boolean = False, errMsg As String = ""
Dim sym As Object = Me.RunLispFunction("read", New Object() {ValueName}, suc, errMsg)
If suc Then
Me.RunLispFunction("set", New Object() {sym, Value}, suc, errMsg)
If suc Then
Return True
Else
Return False
End If
Else
Return False
End If
End FunctionEnd Class
有兴趣的话,可以参考一下。
页:
[1]