找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 923|回复: 1

[精彩文萃] VLISP 对象集合

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2016-9-1 17:17:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 newer 于 2016-9-1 17:22 编辑

bout Collections of Objects (AutoLISP/ActiveX)SHARE


LIKE (0)





All objects in the AutoCAD object model are grouped in collections.
Note: ActiveX support in AutoLISP is limited to Windows only.
For example, the Blocks collection is made up of all blocks in an AutoCAD drawing, and the ModelSpace collection comprises all graphical objects (circles, lines, polylines, and so on) in the drawing's model space.
The following table lists the collections that are part of the AutoCAD object model:
[td]
AutoCAD collection objects
Block
ModelSpace
Blocks
PaperSpace
DimStyles
PlotConfigurations
Documents
PopMenus
FileDependencies
RegisteredApplications
Groups
SelectionSets
Hyperlinks
TextStyles
Layers
Toolbars
Layouts
UCSs
Linetypes
Viewports
Materials
Views
MenuGroups


Retrieving a Member from a Collection
The Item method is used to retrieve a member object from a collection, while the Count property returns the number of items in a collection. Using the Item method and Count property, you can individually process each object in a collection.
For example, you can look at each object in a model space, determine the type of object, and process only the types of objects you are interested in. The following code prints the start angle for each Arc object in model space:
(setq index 0)(repeat (vla-get-count mspace)  (if (= "AcDbArc" (vla-get-objectname (vla-item mspace index)))    (progn      (princ "\nThe start angle of the arc is ")      (princ (vla-get-startangle (vla-item mspace index)))    )  )  (setq index (+ index 1)))Note: Item and Count also apply to groups and selection sets.

Applying a Function to All Items in a Collection
You can use vlax-map-collection to apply a single function to every object in a collection. This can be helpful when you want to list the value of a specific property for each object in a collection, such as each member’s name.
The syntax for the function is:


VLISP 对象集合

VLISP 对象集合


Note:
The preceding example does not show every property returned by vlax-dump-object.

Applying Multiple Expressions to All Items in a Collection
You can use vlax-for to evaluate a series of functions with each object in a collection. This function is much more flexible than using vlax-map-collection. Like the foreach function, vlax-for returns the result of the last expression evaluated inside the for loop.
Note: Modifying the collection (that is, adding or removing members) while iterating through it may cause an error.
The syntax for the function is:
(vlax-for symbolcollection [expressions] ...)
The following example defines a function that uses vlax-for to show color statistics for each object in the active drawing:

This function lists each color in the drawing and the number of objects where the color is found.


  1. (defun show-Color-Statistics (/ objectColor colorSublist colorList)
  2.   (setq modelSpace (vla-get-ModelSpace (vla-get-ActiveDocument
  3.                                                                (vlax-get-Acad-Object)
  4.                                        )
  5.                    )
  6.   )
  7.   (vlax-for obj modelSpace (setq objectColor (vla-get-Color obj))
  8.             (if (setq colorSublist (assoc objectColor colorList))
  9.               (setq colorList (subst
  10.                                 (cons objectColor (1+ (cdr colorSublist)))
  11.                                 colorSublist
  12.                                 colorList
  13.                               )
  14.               )
  15.               (setq colorList (cons (cons objectColor 1) colorList))
  16.             )
  17.   )
  18.   (if colorList
  19.     (progn
  20.       (setq colorList (vl-sort colorList '(lambda (lst1 lst2)
  21.                                             (< (car lst1) (car lst2))
  22.                                           )
  23.                       )
  24.       )
  25.       (princ "\nColorList = ")
  26.       (princ colorList)
  27.       (foreach subList colorList
  28.         (princ "\nColor ")
  29.         (princ (car subList))
  30.         (princ " is found in ")
  31.         (princ (setq count (cdr subList)))
  32.         (princ " object")
  33.         (princ (if (= count 1)
  34.                  "."
  35.                  "s."
  36.                )
  37.         )
  38.       )
  39.     )
  40.   )
  41.   (princ)
  42. )



论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 2476个

财富等级: 金玉满堂

发表于 2016-9-5 08:09:43 | 显示全部楼层
N版写个VLISP方式写块吧...不知道SSGET...VLISP怎么写呀...
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-24 08:33 , Processed in 0.369962 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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