明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2207|回复: 4

[基础] [已解决]如何用Vlisp中的ActiveX方法创建选择集?

[复制链接]
发表于 2009-12-18 16:55 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2009-12-19 12:29:28 编辑

如何用Vlisp中的ActiveX方法创建选择集?
发表于 2009-12-19 09:17 | 显示全部楼层
将选择集内的对象的颜色变为蓝色
  1. (defun selectionvl (/ ssets acadDocument newsset ctr item)
  2.      ;load the visual lisp extensions
  3.   (vl-load-com)
  4.      ;retrieve a reference to the documents object
  5.   (setq acadDocument
  6.   (vla-get-activedocument
  7.     (vlax-get-acad-object)
  8.   )
  9.   )
  10.      ;retrieve a reference to the selection sets object
  11.   (setq ssets (vla-get-selectionsets acadDocument))
  12.      ;add a new selection set
  13.   (setq newsset (vla-add ssets "SS1"))
  14.      ;select your new selection set objects
  15.   (vla-selectOnScreen newsset)
  16.      ;set the counter to zero
  17.   (setq ctr 0)
  18.      ;count the number of objects and loop
  19.   (repeat (vla-get-count newsset)
  20.      ;retrieve each object
  21.     (setq item (vla-item newsset ctr))
  22.      ;check if the entity has a color property
  23.      ;and it can be updated
  24.     (setq check (vlax-property-available-p item "Color" T))
  25.      ;if it can
  26.     (if check
  27.      ;change it's color
  28.       (vlax-put-property item 'Color 5)
  29.     )     ;if
  30.      ;increment the counter
  31.     (setq ctr (1+ ctr))
  32.   )     ;repeat
  33.      ;delete the selection set
  34.   (vla-delete (vla-item ssets "SS1"))
  35.   (princ)
  36. )     ;defun
  37. (princ)
发表于 2009-12-19 09:23 | 显示全部楼层
带过滤的选择集:
(setq newsset (ssget '((8 . "7"))))
  1. (defun selectionvl (/   ssets       acadDocument newsset
  2.       ctr   item       filter_code  filter_value
  3.      )
  4.      ;load the visual lisp extensions
  5.   (vl-load-com)
  6.      ;retrieve a reference to the documents object
  7.   (setq acadDocument
  8.   (vla-get-activedocument
  9.     (vlax-get-acad-object)
  10.   )
  11.   )
  12.      ;retrieve a reference to the selection sets object
  13.   (setq ssets (vla-get-selectionsets acadDocument))
  14.      ;add a new selection set
  15.   (setq newsset (vla-add ssets "SS1"))
  16.      ;create a single element array for the DXF Code
  17.   (setq filter_code (vlax-make-safearray vlax-vbinteger '(0 . 0)))
  18.      ;create a single element array for the value
  19.   (setq filter_value (vlax-make-safearray vlax-vbvariant '(0 . 0)))
  20.      ;DXF Code for layers
  21.   (vlax-safearray-fill filter_code '(8))
  22.      ;the filter value
  23.   (vlax-safearray-fill filter_value '("7"))
  24.      ;Use Select on Screen to select objects on Layer 7
  25.   (vla-selectOnScreen newsset filter_code filter_value)
  26.      ;set the counter to zero
  27.   (setq ctr 0)
  28.      ;count the number of objects and loop
  29.   (repeat (vla-get-count newsset)
  30.      ;retrieve each object
  31.     (setq item (vla-item newsset ctr))
  32.      ;check if the entity has a color property
  33.      ;and it can be updated
  34.     (setq check (vlax-property-available-p item "Color" T))
  35.      ;if it can
  36.     (if check
  37.      ;change it's color
  38.       (vlax-put-property item 'Color 5)
  39.     )     ;if
  40.      ;increment the counter
  41.     (setq ctr (1+ ctr))
  42.   )     ;repeat
  43.      ;delete the selection set
  44.   (vla-delete (vla-item ssets "SS1"))
  45.   (princ)
  46. )
 楼主| 发表于 2009-12-19 11:26 | 显示全部楼层

非常感谢,我一直认为创建选择集的方法为VLA-AddSelectionSets,做了很长时间没做出来 ,另外,添加实体到选择集中的方法除本程序所提供的vla-selectOnScreen(屏幕选择)外,AddItems Items 方法应该也可以吧。

发表于 2009-12-19 11:51 | 显示全部楼层

你说的对,可以的

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-18 05:31 , Processed in 0.407853 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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