PickfirstSelectionSet的疑问
Sub Example_PickfirstSelectionSet()<BR> ' This example lists all the objects in the pickfirst selection set.<BR> ' Before running this example, create some objects in the active<BR> ' drawing and select those objects. The objects currently selected<BR> ' in the active drawing will be returned in the pickfirst selection set.<BR> <BR> Dim pfSS As AcadSelectionSet<BR> Dim ssobject As AcadEntity<BR> Dim msg As String<BR> msg = vbCrLf<BR> <BR> Set pfSS = ThisDrawing.PickfirstSelectionSet<BR> For Each ssobject In pfSS<BR> msg = msg & vbCrLf & ssobject.ObjectName<BR> Next ssobject<BR> MsgBox "The Pickfirst selection set contains: " & msg<BR> <BR>End Sub<BR>这段代码是ACad自带的,在VBA编辑器里运行没有问题,在命令行运行时PickfirstSelectionSet选择集就被清空,是PickfirstSelectionSet的Bug么?如果想实现Lisp的(ssget)函数的功能应该怎么办? 本帖最后由 作者 于 2004-9-27 19:50:33 编辑 <br /><br /> 试试
(defun tls-sub2cmd(filename subname cmdname)<BR> (eval<BR> (list 'defun<BR> (read (strcat "c:" cmdname))<BR> nil<BR> '(if (cadr(ssgetfirst)) (sssetfirst nil (ssget)))<BR> (list 'vla-RunMacro<BR> '(vlax-get-acad-object)<BR> (strcat filename "!" subname)<BR> )<BR> '(sssetfirst nil nil)<BR> '(princ)<BR> )<BR> )<BR> (vlax-add-cmd cmdname (strcat "C:" cmdname))<BR> (princ)<BR>) 在命令行运行要先调用VBARUN命令而取消了实体选择,所以选择集就被清空。应是VBA运行机制的问题。 刚想到一个办法,借助Lisp(ssget)来实现<BR>(defun c:aabbcc()<BR>(ssget)<BR>(command "-vbarun" "aabbcc")<BR>)
Sub aabbcc()<BR> ' This example lists all the objects in the pickfirst selection set.<BR> ' Before running this example, create some objects in the active<BR> ' drawing and select those objects. The objects currently selected<BR> ' in the active drawing will be returned in the pickfirst selection set.<BR> <BR> Dim pfSS As AcadSelectionSet<BR> Dim ssobject As AcadEntity<BR> Dim msg As String<BR> msg = vbCrLf<BR> <BR> Set pfSS = ThisDrawing.ActiveSelectionSet<BR> For Each ssobject In pfSS<BR> msg = msg & vbCrLf & ssobject.ObjectName<BR> Next ssobject<BR> MsgBox "The Pickfirst selection set contains: " & msg<BR> <BR>End Sub<BR> 本帖最后由 作者 于 2004-7-6 22:40:03 编辑 <br /><br /> 以前讨论过这个问题,只有使用事件触发的方法才能确保PickfirstSelectionSet不会丢失。<BR><A href="http://www.mjtd.com/a2/list.asp?id=434" target="_blank" >http://www.mjtd.com/a2/list.asp?id=434</A> 飞弧斑竹的新办法还是不行。
明总方法是对的! 本帖最后由 作者 于 2004-7-7 13:09:48 编辑
下列代码在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]