乐筑天下

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

选择集显示夹点

[复制链接]

2

主题

7

帖子

1

银币

初来乍到

Rank: 1

铜币
15
发表于 2016-10-25 09:15:00 | 显示全部楼层 |阅读模式
使用VLAX类结合VBA可以实现夹点显示。
VLAX类代码:
  1. ' VLAX.CLS v2.0 (Last updated 8/1/2003)
  2. ' Copyright 1999-2001 by Frank Oquendo
  3. '
  4. ' 该程序由乐筑天下修改支持2004版本
  5. '
  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. '
  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.     Dim AcadVersion As Integer
  42.     With ThisDrawing.Application
  43.         AcadVersion = Val(Left(.Version, 2))
  44.         '根据的版本判断使用的VL库类型
  45.         Select Case AcadVersion
  46.             Case Is = 15
  47.                 Set VL = .GetInterfaceObject("VL.Application.1")
  48.             Case Is >= 16
  49.                 Set VL = .GetInterfaceObject("VL.Application.16")
  50.         End Select
  51.     End With
  52.     Set VLF = VL.ActiveDocument.Functions
  53. End Sub
  54. Public Function EvalLispExpression(lispStatement As String)
  55.     '根据LISP表达式调用函数
  56.     Dim sym As Object, ret As Object, retVal
  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.     On Error GoTo 0
  66. End Function
  67. Public Sub SetLispSymbol(symbolName As String, value)
  68.     Dim sym As Object, ret, symValue
  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(symbolName As String)
  77.     Dim sym As Object, ret, symValue
  78.     symValue = value
  79.     Set sym = VLF.Item("read").funcall(symbolName)
  80.     GetLispSymbol = VLF.Item("eval").funcall(sym)
  81. End Function
  82. Public Function GetLispList(symbolName As String) As Variant
  83.     Dim sym As Object, list As Object
  84.     Dim Count, elements(), i As Long
  85.     Set sym = VLF.Item("read").funcall(symbolName)
  86.     Set list = VLF.Item("eval").funcall(sym)
  87.     Count = VLF.Item("length").funcall(list)
  88.     ReDim elements(0 To Count - 1) As Variant
  89.     For i = 0 To Count - 1
  90.         elements(i) = VLF.Item("nth").funcall(i, list)
  91.     Next
  92.     GetLispList = elements
  93. End Function
  94. Public Sub NullifySymbol(ParamArray symbolName())
  95.     Dim i As Integer
  96.     For i = LBound(symbolName) To UBound(symbolName)
  97.         EvalLispExpression "(setq " & CStr(symbolName(i)) & " nil)"
  98.     Next
  99. End Sub
  100. Private Sub Class_Terminate()
  101.     '类析构时,释放内存
  102.     Set VLF = Nothing
  103.     Set VL = Nothing
  104. End Sub

以下为测试代码:
  1. '使用直线选择集测试
  2. Sub ShowSelectLineCrips()
  3.     Dim ss As AcadSelectionSet
  4.     Dim objLine As AcadLine
  5.     Dim fType(0 To 0) As Integer
  6.     Dim fData(0 To 0) As Variant
  7.     Dim AutoSelect As Boolean
  8.     'AutoSelect = True
  9.     On Error Resume Next
  10.     ThisDrawing.SelectionSets("SelectText").Delete
  11.     Set ss = ThisDrawing.SelectionSets.Add("SelectText")
  12.     On Error GoTo 0
  13.     On Error GoTo ErrHandle
  14.     '创建过滤机制
  15.     fType(0) = 0: fData(0) = "LINE"         '直线
  16.     '选择符合条件的所有图元
  17.     If AutoSelect Then
  18.         '自动选择方式
  19.         ss.Select acSelectionSetAll, , , fType, fData
  20.     Else
  21.         '提示用户选择
  22.         ss.SelectOnScreen fType, fData
  23.     End If
  24.     If ss.Count = 0 Then Exit Sub
  25.     '显示夹点
  26.     ShowSelectionSetCrips ss
  27.     '删除数组
  28.     Erase fType: Erase fData
  29.     '删除选择集
  30.     ss.Clear: ss.Delete
  31.     Set ss = Nothing
  32.     Set objLine = Nothing
  33.     Exit Sub
  34. ErrHandle:
  35.     MsgBox Err.Description, vbCritical, "产生了以下错误:"
  36.     Err.Clear
  37. End Sub
  38. '显示选择集中对象的夹点
  39. Public Sub ShowSelectionSetCrips(ByRef ss As AcadSelectionSet)
  40.     Dim LispCode As New VLAX
  41.     Dim objEnt As AcadEntity
  42.     With LispCode
  43.         .EvalLispExpression "(setq ss (ssadd))"
  44.         For Each objEnt In ss
  45.             .EvalLispExpression "(ssadd " & _
  46.                                 "(handent " & Chr(34) & _
  47.                                 objEnt.Handle & Chr(34) & ")" & _
  48.                                 "ss" & _
  49.                                 ")"
  50.         Next
  51.         .EvalLispExpression "(sssetfirst nil ss)"
  52.         .EvalLispExpression "(setq ss nil)"
  53.     End With
  54.     Set LispCode = Nothing
  55.     'MsgBox "您选择了" & ThisDrawing.PickfirstSelectionSet.Count & "个对象"
  56. End Sub

使用上面的代码可以再cad07里实现显示选择集的夹点,在09里Set VL = .GetInterfaceObject("VL.Application.16")这行代码取不到vl对象,所以无法显示夹点.
在cad09中怎么实现显示选择集的夹点呢?
回复

使用道具 举报

3

主题

103

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
115
发表于 2018-4-14 15:34:00 | 显示全部楼层
你这代码有点复杂,其实选择完发个命令行就行(sssetfirst nil (ssget "P"))
回复

使用道具 举报

3

主题

103

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
115
发表于 2019-1-12 10:27:00 | 显示全部楼层
我这也有一版
下面是lisp函数,放在窗体上的文本框里,VL类初始化时加载
  1. (defun VBASelectionSet2ALSelectionSet(VBA_SSName / obj ss sss AL_SS) ;命名选择集转换成aut
  2.   (setq sss (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'SelectionSets))
  3.   (setq ss (vlax-invoke-method sss 'Item VBA_SSName))
  4.   (setq AL_SS(ssadd))
  5.   (vlax-for obj ss
  6.     (ssadd (vlax-vla-object->ename obj) AL_SS)
  7.   )
  8. )

加载代码如下
复制代码
VBA实现函数如下
  1. '命名选择集显示夹点并选中
  2. Public Sub ShowPickPoints(ByVal selectionSet As Object, ByVal blnOpen As Boolean)
  3. If blnOpen = True Then
  4.     vlax.SetLispSymbol "ShowPickPoints_sset", selectionSet.Name
  5.    
  6.     vlax.EvalLispExpression "(sssetfirst nil (VBASelectionSet2ALSelectionSet ShowPickPoints_sset))"
  7.     vlax.NullifySymbol "ShowPickPoints_sset"
  8. Else
  9.     vlax.EvalLispExpression "(sssetfirst nil)"
  10. End If
  11. End Sub
回复

使用道具 举报

2

主题

7

帖子

1

银币

初来乍到

Rank: 1

铜币
15
发表于 2016-10-27 14:59:00 | 显示全部楼层
人工顶一下,有大神吗?
回复

使用道具 举报

16

主题

129

帖子

7

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
196
发表于 2018-1-30 16:55:00 | 显示全部楼层
我的2006前几天还可以实现夹点显示,现在也不行了,搞不清楚怎么回事。取不到VL.Application.16。
回复

使用道具 举报

16

主题

129

帖子

7

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
196
发表于 2018-1-30 16:56:00 | 显示全部楼层
到这句就出错Set VL = .GetInterfaceObject("VL.Application.16")
回复

使用道具 举报

16

主题

129

帖子

7

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
196
发表于 2018-3-1 12:16:00 | 显示全部楼层
在With ThisDrawing.Application的前面加一句ThisDrawing.SendCommand "(vl-load-com)" & vbCr试一下。
回复

使用道具 举报

3

主题

103

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
115
发表于 2018-3-5 16:40:00 | 显示全部楼层
vl不是16版本了
回复

使用道具 举报

11

主题

38

帖子

1

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
82
发表于 2018-4-23 15:01:00 | 显示全部楼层
谢谢分享!!!
回复

使用道具 举报

3

主题

103

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
115
发表于 2018-4-24 12:30:00 | 显示全部楼层
你那是2006还是2016呀,高版本这个vl的com可能没有注册
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2024-11-22 00:30 , Processed in 0.151714 second(s), 72 queries .

© 2020-2024 乐筑天下

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