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)函数的功能应该怎么办?
试试 (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)
) 在命令行运行要先调用VBARUN命令而取消了实体选择,所以选择集就被清空。应是VBA运行机制的问题。 刚想到一个办法,借助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
以前讨论过这个问题,只有使用事件触发的方法才能确保PickfirstSelectionSet不会丢失。
飞弧斑竹的新办法还是不行。
明总方法是对的!
下列代码在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
学习中。。。。。。。。。。
页:
[1]