乐筑天下

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

我用lisp语言编了一个函数,想在acad的vba中调用,vba中怎样才能执行lisp语句呢?[

[复制链接]
god

2

主题

9

帖子

3

银币

初来乍到

Rank: 1

铜币
17
发表于 2003-1-2 09:44:00 | 显示全部楼层 |阅读模式
我用lisp语言编了一个函数,想在acad的vba中调用,vba中怎样才能执行lisp语句呢?[求助][br]我用lisp语言编了一个函数,想在acad的vba中调用,vba中怎样才能执行lisp语句呢?
要求acad的command:命令行中不出现提示信息,用sendkeys和sendcommand都达不到要求。
回复

使用道具 举报

god

2

主题

9

帖子

3

银币

初来乍到

Rank: 1

铜币
17
发表于 2003-1-2 11:56:00 | 显示全部楼层
陈老师,您好
我以前用lisp编了一个比较大的工程专用绘图程序,有几千行吧,使我们单位搞设计用的。计算主程序用的是vb语言,如果把lisp改编成vb或VC语言,工作量太大,所以打算在vb中调用lisp程序,
如果加载lisp能像加载ads和dvb程序一样,有专用的vba命令loadads和loaddvb就好办了,
现在我只知道可以用sendkeys和sendcommand发送字符到acad的命令行,来执行加载和调用lisp程序,这样acad的命令行会出现发送的字符,显得不够专业,而且保密性也不好。
不知您解决过这种问题没有?
回复

使用道具 举报

37

主题

297

帖子

15

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
449
发表于 2003-1-2 13:02:00 | 显示全部楼层

记得原来我发过这样的贴子。
回复

使用道具 举报

god

2

主题

9

帖子

3

银币

初来乍到

Rank: 1

铜币
17
发表于 2003-1-2 13:54:00 | 显示全部楼层
http://www.mjtd.com/bbs/dispbbs.asp?boardid=4&rootid=9981&id=9981
是这个吗?
在acad的帮助文件里有没有这个说
回复

使用道具 举报

god

2

主题

9

帖子

3

银币

初来乍到

Rank: 1

铜币
17
发表于 2003-1-2 15:34:00 | 显示全部楼层
我把里面的那段vba代码贴到acad的vba编辑器里运行,只是出来个world的消息框,command后打了个world的字符串,没搞懂是什么意思,这段代码说明了什么问题?
vl_read和funcall其什么作用? acad的帮助文件里也没有说明,什么地方有这个说明?如何不使用sendcommand在vba中对lisp求值
寄件者:Mark Holder (holderm@atscorporation.com) 主旨:Re: Calling Autolisp Programs From VB - Map 2000 新闻群组:autodesk.autocad.customization.vba View this article only 日期:1999/06/10   
Tony,
Thanks once again for the info. For others who may be interested, I went looking and found the
following link:
http://www.autodesk.com/products/ac...iles/avlisp.exe
The following is an excerpt:
>
Visual LISP as an ActiveX Server
Visual LISP can function as an ActiveX server.  This is useful when using VBA dialogs to control
Visual LISP applications.  For instance, a programmer can create dialogs using the VBA visual
tools for layout. They can then have the actions invoke Visual LISP.
Any Visual LISP function may be invoked and any symbol may have its value referenced or set.
Parameters and results are all variants.  In the following example
Sub Hello()
    Set vla = CreateObject("VL.Application.1")
    Set vld = vla.ActiveDocument
    Set vl_read = vld.Functions.Item("read")
    Set vl_eval = vld.Functions.Item("eval")
    Set vl_hello = vl_read.funcall("(defun hello (x)(print x))")
    Set vl_hello = vl_eval.funcall(vl_hello)
    Set vl_hello = vld.Functions.Item("hello")
    ret = vl_hello.funcall("world")
    MsgBox ret, vbOKOnly
End Sub
we obtain access to Visual LISPs read and eval functions.  We then use those to define a hello
function, which we then call, displaying its return value in a message box.
>
Of interest in it is the phrase &quotarameters and results are all variants". We may get better
results by declaring our variables as variants (which can contain an object) rather than declaring
them directly as objects.
I'm more optimistic about calling VLisp from VB after seeing Autodesk endorse the idea.
Tony Tanzillo wrote:
>The Visual LISP white paper on Autodesk's web page has an example in VBA that should work.
>
回复

使用道具 举报

37

主题

297

帖子

15

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
449
发表于 2003-1-3 09:19:00 | 显示全部楼层
你看程序中调用了lisp函数hello,(hello "world"), 返回值用msgbox显示出来了。
你试着改写一下这个hello函数,比如
(defun hello (x) (strcat "good morning, " x))
回复

使用道具 举报

god

2

主题

9

帖子

3

银币

初来乍到

Rank: 1

铜币
17
发表于 2003-1-3 14:29:00 | 显示全部楼层
改写后有语法错误,可能是引号的原因吧。
这段代码看得似懂非懂,要是哪有详细的说明就好了,我在acad的帮助文件里没找到Functions.Item,funcall等函数的用法。你是在哪看到的?
你有中文的acad的开发帮助文件吗?
回复

使用道具 举报

37

主题

297

帖子

15

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
449
发表于 2003-1-3 15:27:00 | 显示全部楼层
在vba语法中,在字串符中的引号用两个连续的引号代替。
(defun hello (x) (strcat "good morning, " x))
在vba代码中:
Set vl_hello = vl_read.funcall("(defun hello (x) (strcat ""good morning, "" x)) ")
因为是涉及vl的activex对像模型,autocad中没有相关帮助。VL原来并不是
autodesk的产品。
这段代码我没有更详细的资料。只能自己摸索。原文是从google上搜索到的。
看这里:
http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&threadm=37C370F9.CB0D6275%40worldnet.att.net&rnum=1&prev=/groups%3Fq%3DSet%2Bvl_hello%2B%253D%2Bvl_read.funcall%26hl%3Dzh-CN%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D37C370F9.CB0D6275%2540worldnet.att.net%26rnum%3D1
回复

使用道具 举报

god

2

主题

9

帖子

3

银币

初来乍到

Rank: 1

铜币
17
发表于 2003-1-10 12:46:00 | 显示全部楼层
秋枫,按你说的改可以运行,但我改成这样就不行了,为什么? 你帮我看看,好吗?
Set vl_hello = vl_read.funcall("(defun hello (x)  (load  ""a.lsp"")) ")
运行后a.lsp能被调用,但会出现如图示的提示。内容是 run-time error "13"  .  Type mismatch  .   相当于类型错误。
这是所有的代码
Sub Hello()
    Set vla = CreateObject("VL.Application.1")
    Set vld = vla.ActiveDocument
    Set vl_read = vld.Functions.Item("read")
    Set vl_eval = vld.Functions.Item("eval")
Set vl_hello = vl_read.funcall("(defun hello (x)  (load  ""a.lsp"")) ")
Set vl_hello = vl_eval.funcall(vl_hello)
    Set vl_hello = vld.Functions.Item("hello")
    ret = vl_hello.funcall("world")
    MsgBox ret, vbOKOnly
End Sub
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-5-30 12:38 , Processed in 0.605828 second(s), 70 queries .

© 2020-2025 乐筑天下

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