雪山飞狐_lzh 发表于 2004-7-6 21:40:00

PickfirstSelectionSet的疑问

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)函数的功能应该怎么办?

雪山飞狐_lzh 发表于 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)
)

莫名 发表于 2004-7-6 22:01:00

在命令行运行要先调用VBARUN命令而取消了实体选择,所以选择集就被清空。应是VBA运行机制的问题。

雪山飞狐_lzh 发表于 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

mccad 发表于 2004-7-6 22:13:00


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

莫名 发表于 2004-7-6 22:19:00

飞弧斑竹的新办法还是不行。
明总方法是对的!

雪山飞狐_lzh 发表于 2004-7-6 22:53:00


下列代码在Cad2005及2002中测试通过 Lisp代码
(defun c:aabbcc()
(setvar "cmdecho" 0)
(if (ssget) (command "-vbarun" "aabbcc"))
(setvar "cmdecho" 1)
(princ)
)VBA代码
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 thos   e 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 = vbCrLfa
      
       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

zzh_my 发表于 2007-5-9 14:58:00

学习中。。。。。。。。。。
页: [1]
查看完整版本: PickfirstSelectionSet的疑问