VLA 增加选集的方法

- (vl-load-com)
- (defun c:Example_Select()
- ;; This example adds members to a selection set, first by crossing and
- ;; then by filtering for circles.
- (setq acadObj (vlax-get-acad-object))
- (setq doc (vla-get-ActiveDocument acadObj))
- ;; Create the selection set
- (setq ssetObj (vla-Add (vla-get-SelectionSets doc) "SSET"))
-
- ;; Add all object to the selection set that lie within a crossing of (28,17,0) and
- ;; (-3.3, -3.6,0)
- (setq mode acSelectionSetCrossing
- corner1 (vlax-3d-point 28 17 0)
- corner2 (vlax-3d-point -3.3 -3.6 0))
- (vla-Select ssetObj mode corner1 corner2)
- (alert (strcat "Objects selected: " (itoa (vla-get-Count ssetObj))))
- (vla-Clear ssetObj)
-
- ;; Add all the Circles to the selection set that lie within the crossing of (28,17,0) and
- ;; (-3.3, -3.6,0) by filtering from the current drawing
- (setq gpCode (vlax-make-safearray vlax-vbInteger '(0 . 0)))
- (vlax-safearray-put-element gpCode 0 0)
- (setq dataValue (vlax-make-safearray vlax-vbVariant '(0 . 0)))
- (vlax-safearray-put-element dataValue 0 "Circle")
-
- (vla-Select ssetObj mode corner1 corner2 gpCode dataValue)
- (alert (strcat "Objects selected: " (itoa (vla-get-Count ssetObj))))
- (vla-Delete ssetObj)
- )
vla 选集的三个方法 clear erase delete 的区别
1 Clear 把选集中的索引对应的对象清除,选集对象保留,count 不变,Selectionsets 中仍保留 选集
2 Erase 选集对象的索引删除,选集对象保留,此时 count = 0,Selectionsets 中仍保留 选集
3 Delete 选集对象从Selectionsets 中删除,索引清除
Selectionsets 中的 CURRENT
在 ACAD 中只要进行了选择(ssget、select 、VBA、vla方法),ACAD 后台自动更新 CURRENT 选集内的索引,该选集在 VBA 中总可以正确遍历,但在 VLA 方法时存在一个 BUG,这个 BUG 只要清理一次,以后都可以正确使用。
一般autolisp中使用 ssget 构造选集比 vla 的选择更方便,但是如果对实体使用 vla 操作一般有两种方法
1 vlax-ename->vla-object 转化

- (if (setq ss (ssget))
- (progn
- (setq i 0)
- (while (setq e (ssname ss i))
- (setq obj (vlax-ename->vla-object e))
- ....
- (setq i (1+ i))
- )
- )
- )
2 使用 activeselectionset 即 CURRENT 选集
- (if (ssget)
- (vlax-for obj (vla-get-activeselectionset curdoc)
- ....
- )
- )
复制代码
其中清理方法 见论坛以前帖子 clearcset
|