明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 6489|回复: 7

PickfirstSelectionSet的疑问

[复制链接]
发表于 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)函数的功能应该怎么办?
 楼主| 发表于 2004-8-22 00:15:00 | 显示全部楼层
本帖最后由 作者 于 2004-9-27 19:50:33 编辑

试试 (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)
)
回复 支持 0 反对 1

使用道具 举报

发表于 2004-7-6 22:01:00 | 显示全部楼层
在命令行运行要先调用VBARUN命令而取消了实体选择,所以选择集就被清空。应是VBA运行机制的问题。
 楼主| 发表于 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
发表于 2004-7-6 22:13:00 | 显示全部楼层
本帖最后由 作者 于 2004-7-6 22:40:03 编辑

以前讨论过这个问题,只有使用事件触发的方法才能确保PickfirstSelectionSet不会丢失。
http://www.mjtd.com/a2/list.asp?id=434
发表于 2004-7-6 22:19:00 | 显示全部楼层
飞弧斑竹的新办法还是不行。


明总方法是对的!
 楼主| 发表于 2004-7-6 22:53:00 | 显示全部楼层
本帖最后由 作者 于 2004-7-7 13:09:48 编辑

下列代码在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
发表于 2007-5-9 14:58:00 | 显示全部楼层
学习中。。。。。。。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-23 07:17 , Processed in 0.207382 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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