明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 6895|回复: 15

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

  [复制链接]
发表于 2003-1-2 09:44:00 | 显示全部楼层 |阅读模式
我用lisp语言编了一个函数,想在acad的vba中调用,vba中怎样才能执行lisp语句呢?[求助][br]我用lisp语言编了一个函数,想在acad的vba中调用,vba中怎样才能执行lisp语句呢?

要求acad的command:命令行中不出现提示信息,用sendkeys和sendcommand都达不到要求。
发表于 2003-1-2 09:46:00 | 显示全部楼层

为什么要这样做?VLISP不能完成您的需求,必须用VBA么?

 楼主| 发表于 2003-1-2 11:56:00 | 显示全部楼层

陈老师,您好

陈老师,您好

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

这个你可以试试使用vl.application.1 对象。vl本身提供了COM接口。

本帖最后由 作者 于 2003-1-2 13:02:18 编辑

记得原来我发过这样的贴子。
 楼主| 发表于 2003-1-2 13:54:00 | 显示全部楼层

是这个吗? http://www.mjtd.com/bbs/dispbbs.asp?boardid=4&rootid=9981&id=9981

http://www.mjtd.com/bbs/dispbbs.asp?boardid=4&rootid=9981&id=9981

是这个吗?

在acad的帮助文件里有没有这个说
 楼主| 发表于 2003-1-2 15:34:00 | 显示全部楼层

vl_read和funcall其什么作用?没搞懂

我把里面的那段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:

<<snip>>
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.
<<snip>>

Of interest in it is the phrase "arameters 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:
<<snip>>The Visual LISP white paper on Autodesk's web page has an example in VBA that should work.
<<snip>>
发表于 2003-1-3 09:19:00 | 显示全部楼层

world的消息框就是求值结果啊。

你看程序中调用了lisp函数hello,(hello "world"), 返回值用msgbox显示出来了。

你试着改写一下这个hello函数,比如
(defun hello (x) (strcat "good morning, " x))
 楼主| 发表于 2003-1-3 14:29:00 | 显示全部楼层

秋风是不是在这也当斑竹啊,你是xdcad的秋枫吧?我猜你姓邱

改写后有语法错误,可能是引号的原因吧。

这段代码看得似懂非懂,要是哪有详细的说明就好了,我在acad的帮助文件里没找到Functions.Item,funcall等函数的用法。你是在哪看到的?

你有中文的acad的开发帮助文件吗?
发表于 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
 楼主| 发表于 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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-21 17:38 , Processed in 0.176855 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表