找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1527|回复: 2

Accessing LDATA values from VBA

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2021-1-11 20:33:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

问题:
A VLISP function can be used to create a dictionary just like:

(vlax-ldata-put "Test" "Helper" "Good")

And a dictionary named "Test" is created, and a (vlax-ldata-get "Test" "Helper")
retrieves the return value, "Good". From VBA, how can I get the dictionary data
value of "Good"?

解答:

VLISP ldata is attached to a custom object with class name "vlo_VL" and then the
object is added to the Named Object Dictionary. However, a custom object is not
penetrable by means of the VBA object model alone.  You cannot create custom
entities/objects with VBA, buty ou can develop custom entities with ObjectARX
and create an ActiveX interface to it so that it can be used within VBA.
Unfortunately, there is no direct interface (or Automation server) to a vlo_VL
object.

The AutoCAD 2000 Visual LISP Automation server (an unsupported interface) can be
used to bridge the gap between VBA macro and the LISP environment, though.

If the following has already been entered successfully at the command line:
(vl-load-com)
(vlax-ldata-put "Test" "Helper" "Good")
Then, with a little effort a VBA macro can use the LISP server's generalized
object model:
  1. Function readEvalHelper(app As Object)
  2.    ' this is a helper function
  3.    Set vld = app.ActiveDocument

  4.    Dim vlf_read As Object
  5.    Set vlf_read = vld.Functions.Item("read")

  6.    Dim vl_obj1 As Object
  7.    Set vl_obj1 = vlf_read.funcall("(defun read-eval (arg)(eval (read arg)))")

  8.    Dim vlf_eval As Object
  9.    Set vlf_eval = vld.Functions.Item("eval")

  10.    Dim vl_obj2 As Object
  11.    Set vl_obj2 = vlf_eval.funcall(vl_obj1)

  12. End Function


  13. Public Sub vlsGetLData()
  14.      Dim vlApp As Object
  15.      Set vlApp = CreateObject("VL.Application.1")

  16.      readEvalHelper vlApp

  17.      Dim invokeIt As Object
  18.      Set invokeIt = vlApp.ActiveDocument.Functions.Item("read-eval")
  19.      invokeIt.funcall ("(setq lDatum (vlax-ldata-get ""Test"" ""Helper""))")

  20.      Set sym = vlApp.ActiveDocument.Functions.Item("read").funcall("lDatum")
  21.      GetLispSym = vlApp.ActiveDocument.Functions.Item("eval").funcall(sym)
  22.      MsgBox ("Key's data is:" + Chr(13) + GetLispSym)

  23. End Sub

See also DevNote #30485 for more discussion and illustrated examples of how to
exploit Visual LISP Server.

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 1个

财富等级: 恭喜发财

发表于 2021-11-5 09:12:52 | 显示全部楼层
这个好像得改16
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1094个

财富等级: 财源广进

发表于 2022-3-27 07:50:41 | 显示全部楼层
感谢楼主分享!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-12-14 06:22 , Processed in 0.363780 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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