乐筑天下

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

PickfirstSelectionSet的疑问

[复制链接]

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2004-7-6 21:40:00 | 显示全部楼层 |阅读模式
Sub Example_PickfirstSelectionSet()
                         ' This example lists all the objects in the pickfirst selection set.
                         ' Before running this example, create some objects in the active
                         ' drawing and select those objects. The objects currently selected
                         ' in the active drawing will be returned in the pickfirst selection set.
                                                                                         
                         Dim pfSS As AcadSelectionSet
                         Dim ssobject As AcadEntity
                         Dim msg As String
                         msg = vbCrLf
                         
                         Set pfSS = ThisDrawing.PickfirstSelectionSet
                         For Each ssobject In pfSS
                                                         msg = msg & vbCrLf & ssobject.ObjectName
                         Next ssobject
                         MsgBox "The Pickfirst selection set contains: " & msg
                         
End Sub
这段代码是ACad自带的,在VBA编辑器里运行没有问题,在命令行运行时PickfirstSelectionSet选择集就被清空,是PickfirstSelectionSet的Bug么?
如果想实现Lisp的(ssget)函数的功能应该怎么办?
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2004-8-22 00:15:00 | 显示全部楼层

试试 (defun tls-sub2cmd(filename subname cmdname)
        (eval
         (list 'defun
                 (read (strcat "c:" cmdname))
                 nil
                 '(if (cadr(ssgetfirst)) (sssetfirst nil (ssget)))
                 (list 'vla-RunMacro
                                                                 '(vlax-get-acad-object)
                                                                         (strcat filename "!" subname)
                 )
                 '(sssetfirst nil nil)
                 '(princ)
         )
        )
        (vlax-add-cmd cmdname (strcat "C:" cmdname))
        (princ)
)
回复

使用道具 举报

21

主题

166

帖子

7

银币

后起之秀

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

铜币
250
发表于 2004-7-6 22:01:00 | 显示全部楼层
在命令行运行要先调用VBARUN命令而取消了实体选择,所以选择集就被清空。应是VBA运行机制的问题。
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2004-7-6 22:10:00 | 显示全部楼层
刚想到一个办法,借助Lisp(ssget)来实现
(defun c:aabbcc()
(ssget)
(command "-vbarun" "aabbcc")
)
Sub aabbcc()
                         ' This example lists all the objects in the pickfirst selection set.
                         ' Before running this example, create some objects in the active
                         ' drawing and select those objects. The objects currently selected
                         ' in the active drawing will be returned in the pickfirst selection set.
                                                                                         
                         Dim pfSS As AcadSelectionSet
                         Dim ssobject As AcadEntity
                         Dim msg As String
                         msg = vbCrLf
                         
                         Set pfSS = ThisDrawing.ActiveSelectionSet
                         For Each ssobject In pfSS
                                                         msg = msg & vbCrLf & ssobject.ObjectName
                         Next ssobject
                         MsgBox "The Pickfirst selection set contains: " & msg
                         
End Sub
回复

使用道具 举报

158

主题

2315

帖子

10

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2951
发表于 2004-7-6 22:13:00 | 显示全部楼层

以前讨论过这个问题,只有使用事件触发的方法才能确保PickfirstSelectionSet不会丢失。
回复

使用道具 举报

21

主题

166

帖子

7

银币

后起之秀

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

铜币
250
发表于 2004-7-6 22:19:00 | 显示全部楼层
飞弧斑竹的新办法还是不行。
明总方法是对的!
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2004-7-6 22:53:00 | 显示全部楼层

下列代码在Cad2005及2002中测试通过 Lisp代码
  1. (defun c:aabbcc()
  2. (setvar "cmdecho" 0)
  3. (if (ssget) (command "-vbarun" "aabbcc"))
  4. (setvar "cmdecho" 1)
  5. (princ)
  6. )
VBA代码
  1. Sub aabbcc()
  2.        ' This example lists all the objects in the pickfirst selection set.
  3.        ' Before running this example, create some objects in the active
  4.        ' drawing and select thos     e objects. The objects currently selected
  5.        ' in the active drawing will be returned in the pickfirst selection set.
  6.                        
  7.        Dim pfSS As AcadSelectionSet
  8.        Dim ssobject As AcadEntity
  9.        Dim msg As String
  10.        msg = vbCrLfa
  11.       
  12.        Set pfSS = ThisDrawing.ActiveSelectionSet
  13.       
  14.        For Each ssobject In pfSS
  15.                msg = msg & vbCrLf & ssobject.ObjectName
  16.        Next ssobject
  17.        MsgBox "The Pickfirst selection set contains: " & msg
  18.       
  19. End Sub
回复

使用道具 举报

0

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
3
发表于 2007-5-9 14:58:00 | 显示全部楼层
学习中。。。。。。。。。。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-7 19:07 , Processed in 1.031241 second(s), 69 queries .

© 2020-2025 乐筑天下

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