明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: lihengmin

[求助]怎样用VBA读取CASS软件内每个界址线段的扩展属性

  [复制链接]
发表于 2007-12-25 22:03:00 | 显示全部楼层
把下面的代码放到VLAX类代码里
  1. ' VLAX.CLS v2.0 (Last updated 8/1/2003)
  2. ' Copyright 1999-2001 by Frank Oquendo
  3. '
  4. ' 该程序由明经通道修改支持2004版本
  5. ' http://www.mjtd.com
  6. '
  7. ' Permission to use, copy, modify, and distribute this software
  8. ' for any purpose and without fee is hereby granted, provided
  9. ' that the above copyright notice appears in all copies and
  10. ' that both that copyright notice and the limited warranty and
  11. ' restricted rights notice below appear in all supporting
  12. ' documentation.
  13. '
  14. ' FRANK OQUENDO (THE AUTHOR) PROVIDES THIS PROGRAM "AS IS" AND WITH
  15. ' ALL FAULTS. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY
  16. ' OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  THE AUTHOR
  17. ' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  18. ' UNINTERRUPTED OR ERROR FREE.
  19. '
  20. ' Use, duplication, or disclosure by the U.S. Government is subject to
  21. ' restrictions set forth in FAR 52.227-19 (Commercial Computer
  22. ' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
  23. ' (Rights in Technical Data and Computer Software), as applicable.
  24. '
  25. ' VLAX.cls allows developers to evaluate AutoLISP expressions from
  26. ' Visual Basic or VBA
  27. '
  28. ' Notes:
  29. ' All code for this class module is publicly available througout various posts
  30. ' at news://discussion.autodesk.com/autodesk.autocad.customization.vba. I do not
  31. ' claim copyright or authorship on code presented in these posts, only on this
  32. ' compilation of that code. In addition, a great big "Thank you!" to Cyrille Fauvel
  33. ' demonstrating the use of the VisualLISP ActiveX Module.
  34. '
  35. ' Dependencies:
  36. ' Use of this class module requires the following application:
  37. ' 1. VisualLISP
  38. Private VL As Object
  39. Private VLF As Object
  40. Private Sub Class_Initialize()
  41.     If Left(ThisDrawing.Application.Version, 2) = "15" Then
  42.      Set VL = GetInterfaceObject("VL.Application.1")
  43.     ElseIf Left(ThisDrawing.Application.Version, 2) = "16" Then
  44.      Set VL = GetInterfaceObject("VL.Application.16")
  45.     ElseIf Left(ThisDrawing.Application.Version, 2) = "17" Then
  46.      Set VL = GetInterfaceObject("VL.Application.16")
  47.     End If
  48.     Set VLF = VL.ActiveDocument.Functions
  49. End Sub
  50. Private Sub Class_Terminate()
  51.     Set VLF = Nothing
  52.     Set VL = Nothing
  53. End Sub
  54. Public Function EvalLispExpression(ByVal lispStatement As String)
  55.     Dim sym As Object, RET As Object, RetVal
  56.    
  57.     Set sym = VLF.Item("read").funcall(lispStatement)
  58.     On Error Resume Next
  59.     RetVal = VLF.Item("eval").funcall(sym)
  60.     If Err Then
  61.         EvalLispExpression = ""
  62.     Else
  63.         EvalLispExpression = RetVal
  64.     End If
  65. End Function
  66. Public Sub SetLispSymbol(ByVal symbolName As String, ByVal Value)
  67.     Dim sym As Object, RET, symvalue
  68.    
  69.     symvalue = Value
  70.     Set sym = VLF.Item("read").funcall(symbolName)
  71.     RET = VLF.Item("set").funcall(sym, symvalue)
  72.     EvalLispExpression "(defun translate-variant (data) (cond ((= (type data) 'list) (mapcar 'translate-variant data)) ((= (type data) 'variant) (translate-variant (vlax-variant-value data))) ((= (type data) 'safearray) (mapcar 'translate-variant (vlax-safearray->list data))) (t data)))"
  73.     EvalLispExpression "(setq " & symbolName & "(translate-variant " & symbolName & "))"
  74.     EvalLispExpression "(setq translate-variant nil)"
  75. End Sub
  76. Public Function GetLispSymbol(ByVal symbolName As String)
  77.     Dim sym As Object, RET, symvalue
  78.    
  79.     symvalue = Value
  80.     Set sym = VLF.Item("read").funcall(symbolName)
  81.     GetLispSymbol = VLF.Item("eval").funcall(sym)
  82. End Function
  83. Public Function GetLispList(ByVal symbolName As String) As Variant
  84.    Dim sym As Object, list As Object
  85.    Dim Count, elements(), i As Long
  86.    
  87.    Set sym = VLF.Item("read").funcall(symbolName)
  88.    Set list = VLF.Item("eval").funcall(sym)
  89.    
  90.    Count = VLF.Item("length").funcall(list)
  91.    
  92.    ReDim elements(0 To Count - 1) As Variant
  93.    
  94.    For i = 0 To Count - 1
  95.         elements(i) = VLF.Item("nth").funcall(i, list)
  96.    Next
  97.    
  98.    GetLispList = elements
  99.    
  100. End Function
  101. Public Sub NullifySymbol(ParamArray symbolName())
  102.     Dim i As Integer
  103.    
  104.     For i = LBound(symbolName) To UBound(symbolName)
  105.         EvalLispExpression "(setq " & CStr(symbolName(i)) & " nil)"
  106.     Next
  107. End Sub
 楼主| 发表于 2007-12-25 23:21:00 | 显示全部楼层

导入了VLAX.CLS类,

Dim VL As New VLAX 

Private Sub Class_Initialize()
    If Left(ThisDrawing.Application.Version, 2) = "15" Then
        Set VL = ThisDrawing.Application.GetInterfaceObject("VL.Application.1")
    ElseIf Left(ThisDrawing.Application.Version, 2) = "16" Then
        Set VL = ThisDrawing.Application.GetInterfaceObject("VL.Application.16")
    End If
    Set VLF = VL.ActiveDocument.Functions
End Sub

运行到此处总是跳转到错误处理语句?!不知道如何解决。我用的是CAD2004中文版

发表于 2007-12-25 23:28:00 | 显示全部楼层

新建一个类模块,把名字改成Vlax

再把11楼的代码Copy进去

 楼主| 发表于 2007-12-25 23:42:00 | 显示全部楼层

对啊,我考进去了,但每次选择后提示“错误选择”

后我把错误处理的去掉后再运行

到Set VL = GetInterfaceObject("VL.Application.16")出错“运行时错误-2147220999(800401放):加载应用程序时出现问题”
    

 楼主| 发表于 2007-12-26 00:17:00 | 显示全部楼层

对了,9楼的LIST代码我没用,还要用他吗?麻烦您指点

 楼主| 发表于 2007-12-26 02:03:00 | 显示全部楼层

(vl-load-com)

运行上面的语句已基本可以了,谢谢您 

 楼主| 发表于 2007-12-26 02:24:00 | 显示全部楼层

Public Function GetLispList(ByVal symbolName As String) As Variant
    Dim sym As Object, list As Object
    Dim Count, elements(), i As Long
   
    Set sym = VLF.Item("read").funcall(symbolName)
    Set list = VLF.Item("eval").funcall(sym)
   
    Count = VLF.Item("length").funcall(list)
   
    ReDim elements(0 To Count - 1) As Variant
   
    For i = 0 To Count - 1
         elements(i) = VLF.Item("nth").funcall(i, list)
    Next
   
    GetLispList = elements
   
End Function

当运行到上面标颜色的语句时出现如下错误:

运行时错误 2000
no function definition: GETVERS

发表于 2007-12-26 10:13:00 | 显示全部楼层
lisp代码放在acad2004doc.lsp文件里
 楼主| 发表于 2007-12-26 13:19:00 | 显示全部楼层

十分感谢您的指点,我的QQ106130523,希望能继续得到您的帮助

发表于 2015-1-21 11:34:47 | 显示全部楼层
雪山飞狐_lzh 发表于 2007-12-25 11:52
CASS把Xdata放在Vertex对象了,而VBA的对象模型没有提供该对象
可以将多段线的handle依次循环加一, ...

飞狐,请问这个对应C# 应该怎么做呢?我没有查到相应的方法,我在网上也只查到这一条相关的信息。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 12:27 , Processed in 0.188423 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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