AutoCAD 对象模型中的所有对象都分组在集合中。 注意:AutoLISP 中的 ActiveX 支持仅限于 Windows。
例如,“块”集合由 AutoCAD 图形中的所有块组成,而“模型空间”集合包含图形模型空间中的所有图形对象(圆、线、折线等)。 下表列出了属于 AutoCAD 对象模型的集合:
从集合中检索成员该方法用于从集合中检索成员对象,而属性返回集合中的项数。使用方法和属性,可以单独处理集合中的每个对象。ItemCountItemCount 例如,您可以查看模型空间中的每个对象,确定对象的类型,并仅处理您感兴趣的对象类型。以下代码打印模型空间中每个对象的起始角度:Arc (setq index 0) (repeat (vla-get-count mspace) (if (= "AcDbArc" (vla-get-objectname (vla-item mspace index))) (progn (prompt "\nThe start angle of the arc is ") (prompt (rtos (vla-get-startangle (vla-item mspace index)))) ) ) (setq index (+ index 1)) ) 注意:项目和计数也适用于组和选择集。
将函数应用于集合中的所有项可以使用将单个函数应用于集合中的每个对象。如果要列出集合中每个对象(如每个成员的名称)的特定属性的值,这会很有帮助。vlax-map-collection 该函数的语法为: (vlax-map-collection collection-object function) 例如,以下命令显示图形模型空间中每个对象的所有特性: (vlax-map-collection (vla-get-ModelSpace acadDocument) 'vlax-dump-Object) ; IAcadLWPolyline: AutoCAD Lightweight Polyline Interface ; Property values: ; Application (RO) = #<VLA-OBJECT IAcadApplication 00b3b91c> ; Area (RO) = 3.67152 ; Closed = -1 ; Color = 256 ; Coordinates = (9.59247 4.44872 9.25814 5.34715 4.1991 5.679 ...) ; EntityName (RO) = "AcDbPolyline" ; EntityType (RO) = 24 ; Handle (RO) = "4C" ; Layer = "0" ; . ; . ; . ; Thickness = 0.0 ; Visible = -1 Note: The preceding example does not show every property returned by
.
vlax-dump-object
Applying Multiple Expressions to All Items in a CollectionYou can use to evaluate a series of functions with each object in a collection. This function is much more flexible than using . Like the function, returns the result of the last expression evaluated inside the for loop. vlax-forvlax-map-collectionforeachvlax-for 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 to show color statistics for each object in the active drawing: vlax-for (defun show-Color-Statistics (/ objectColor colorSublist colorList) (setq modelSpace (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-Acad-Object)) ) ) (vlax-for obj modelSpace (setq objectColor (vla-get-Color obj)) (if (setq colorSublist (assoc objectColor colorList)) (setq colorList (subst (cons objectColor (1+(cdr colorSublist))) colorSublist colorList ) ) (setq colorList (cons (cons objectColor 1) colorList)) ) ) (if colorList (progn (setq colorList (vl-sort colorList '(lambda (lst1 lst2) (< (car lst1) (car lst2))) ) ) (princ "\nColorList = ") (princ colorList) (foreach subList colorList (princ "\nColor ") (princ (car subList)) (princ " is found in ") (princ (setq count (cdr subList))) (princ " object") (princ (if (= count 1) "." "s." ) ) ) ) ) (princ) ) 此功能列出图形中的每种颜色以及找到该颜色的对象数。 |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )
GMT+8, 2024-5-19 12:43
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.