乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 84|回复: 6

[求助]C#编写的函数,有办法于LISP中呼叫并将运算资料进行传递吗?

[复制链接]

35

主题

58

帖子

6

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2014-3-4 13:14:00 | 显示全部楼层 |阅读模式
请教各位高手
C#编写的函数,有办法于LISP中呼叫并将运算资料进行传递吗?
烦请各位能够协助解答一下,谢谢~
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2014-3-4 14:50:00 | 显示全部楼层
不明白楼主的问题
不过C#可以定义Lisp函数供Lisp使用,C#也可以使用Lisp函数(需要注册)
---------------------------
这里是说在较新版本的AutoCAD
回复

使用道具 举报

35

主题

58

帖子

6

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2014-3-4 14:53:00 | 显示全部楼层
谢谢解答~请问您说的部份哪边可以找到范例资料呢?是否可以提供,谢谢~
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2014-3-4 16:55:00 | 显示全部楼层
http://user.qzone.qq.com/812928665/infocenter?ptsig=VqFz*FJZppcBJ8FFEY8WcJIsdH05z0cArysBaljnHFU_
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2014-3-4 16:59:00 | 显示全部楼层
上面连接好像有问题,
就是空间里面的日志
回复

使用道具 举报

84

主题

543

帖子

12

银币

中流砥柱

Rank: 25

铜币
886
发表于 2014-3-4 23:14:00 | 显示全部楼层
建议LZ先看看有关C#与Lisp语言混合编程这方面的就可以实现你的要求了
回复

使用道具 举报

75

主题

306

帖子

10

银币

中流砥柱

Rank: 25

铜币
606
发表于 2014-3-25 15:24:00 | 显示全部楼层
  1. '''
  2. ''' 用.NET来运行Lisp的工具
  3. '''
  4. ''' 1.实例化后,先LoadLisp
  5. Public Class LispInDotNet
  6.     Private mVlFunctions As Object = Nothing
  7.     '''
  8.     ''' Lisp的函数对象集
  9.     '''
  10.     '''
  11.     '''
  12.     '''
  13.     Public ReadOnly Property VlFunctions As Object
  14.         Get
  15.             Return mVlFunctions
  16.         End Get
  17.     End Property
  18.     Private mLoadSuccessful As Boolean = False
  19.     '''
  20.     ''' 是否加载成功
  21.     '''
  22.     '''
  23.     '''
  24.     '''
  25.     Public ReadOnly Property LoadSuccessful As Boolean
  26.         Get
  27.             Return mLoadSuccessful
  28.         End Get
  29.     End Property
  30.     '''
  31.     ''' 加载Lisp运行环境
  32.     '''
  33.     '''
  34.     '''
  35.     Public Function LoadLisp() As Boolean
  36.         '状态:20131126-1348测试通过
  37.         Try
  38.             Dim acadApp As Object = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
  39.             Dim vlApp As Object = acadApp.GetInterfaceObject("VL.Application.16") '此处出错,可能是因为没有加载VL环境所致, (vl-load-com)
  40.             'VL.Application.16 为什么会是16?到AutoCAD各版本的安装目录里到查找,会发现一个vl16.tlb,这个文件就是visual lisp的运行环境,到AutoCAD 2014为止,这个文件一直没有更新。
  41.             mVlFunctions = vlApp.ActiveDocument.Functions
  42.             mLoadSuccessful = True
  43.             Return True
  44.         Catch ex As Autodesk.AutoCAD.Runtime.Exception
  45.             Return False
  46.         End Try
  47.     End Function
  48.     '''
  49.     ''' 运行Lisp函数
  50.     '''
  51.     '''
  52.     ''' 参数数组
  53.     ''' 是否运行成功
  54.     ''' 出错信息
  55.     '''
  56.     '''
  57.     Public Function RunLispFunction(ByVal FunctionName As String, args() As Object, Optional ByRef runSuccessful As Boolean = False, Optional ByRef ErrMsg As String = "") As Object
  58.         '状态:20131126-1711通过测试
  59.         runSuccessful = False
  60.         If Me.LoadSuccessful = True Then
  61.             If Me.HasLispFunction(FunctionName) = False Then
  62.                 Return Nothing
  63.             End If
  64.             Try
  65.                 Dim vlFunction As Object = mVlFunctions.Item(FunctionName)
  66.                 RunLispFunction = vlFunction.GetType.InvokeMember("funcall", BindingFlags.InvokeMethod, Nothing, vlFunction, args)
  67.                 runSuccessful = True
  68.             Catch ex As System.Reflection.TargetInvocationException
  69.                 ErrMsg = ex.Message
  70.                 Return Nothing
  71.             End Try
  72.         Else
  73.             Return Nothing
  74.         End If
  75.     End Function
  76.     '''
  77.     ''' 查询当前环境是否有某个Lisp函数或者变量
  78.     '''
  79.     '''
  80.     '''
  81.     '''
  82.     Public Function HasLispFunction(ByVal functionNameOrValueName As String) As Boolean
  83.         '状态:20131126-1534通过测试
  84.         Dim vlFunction As Object = mVlFunctions.Item("read")
  85.         Dim sym As Object = vlFunction.GetType.InvokeMember("funcall", BindingFlags.InvokeMethod, Nothing, vlFunction, New Object() {functionNameOrValueName})
  86.         If sym Is Nothing Then
  87.             Return False
  88.         Else
  89.             Dim vlFuncEval As Object = mVlFunctions.Item("eval")
  90.             If vlFunction.GetType.InvokeMember("funcall", BindingFlags.InvokeMethod, Nothing, vlFuncEval, New Object() {sym}) Is Nothing Then
  91.                 Return False
  92.             Else
  93.                 Return True
  94.             End If
  95.         End If
  96.     End Function
  97.     '''
  98.     ''' 获取Lisp变量的值
  99.     '''
  100.     '''
  101.     '''
  102.     '''
  103.     Public Function GetValue(ValueName As String) As Object
  104.         '状态:20131126-1534通过测试
  105.         Return Eval(ValueName)
  106.     End Function
  107.     '''
  108.     ''' 获取一个Lisp语句的值
  109.     '''
  110.     '''
  111.     '''
  112.     '''
  113.     Public Function Eval(LispString As String) As Object
  114.         '状态:20131126-1534通过测试
  115.         Try
  116.             Dim sym As Object = RunLispFunction("read", New Object() {LispString})
  117.             If sym Is Nothing Then
  118.                 Return Nothing
  119.             Else
  120.                 Return RunLispFunction("eval", New Object() {sym})
  121.             End If
  122.         Catch ex As Exception
  123.             Return Nothing
  124.         End Try
  125.     End Function
  126.     '''
  127.     ''' 设置Lisp变量的值
  128.     '''
  129.     ''' 变量名
  130.     ''' 变量值
  131.     '''
  132.     '''
  133.     Public Function SetValue(ByVal ValueName As String, ByVal Value As Object) As Boolean
  134.         '状态:20131126-1534通过测试
  135.         Dim suc As Boolean = False, errMsg As String = ""
  136.         Dim sym As Object = Me.RunLispFunction("read", New Object() {ValueName}, suc, errMsg)
  137.         If suc Then
  138.             Me.RunLispFunction("set", New Object() {sym, Value}, suc, errMsg)
  139.             If suc Then
  140.                 Return True
  141.             Else
  142.                 Return False
  143.             End If
  144.         Else
  145.             Return False
  146.         End If
  147.     End FunctionEnd Class

有兴趣的话,可以参考一下。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 13:16 , Processed in 0.368969 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表