本帖最后由 kucha007 于 2024-1-22 19:50 编辑
两个函数达成的效果一致,可以配合高飞鸟大神的矩阵函数达成不一样的玩法
函数一:
- ;获取全部块内对象
- ;BlkObj为图元时返回图元表, BlkObj为对象时返回vl对象表
- (defun K:GetAllObj4Blk (BlkObj / EnFlag Lst XX )
- (if (null vlax-dump-object) (vl-load-com));;将Visual LISP扩展功能加载到AutoLISP
- (setq EnFlag Nil Lst nil)
- (if (eq (type BlkObj) 'ENAME)
- (setq EnFlag T
- BlkObj (Vlax-Ename->Vla-Object BlkObj)
- )
- )
- (vlax-for XX
- (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
- (Vlax-Get BlkObj 'Name);块名
- )
- (setq Lst (cons XX Lst))
- )
- (if EnFlag (mapcar 'vlax-vla-object->ename Lst) Lst)
- )
函数二:
- ;获取全部块内对象
- ;BlkObj为图元时返回图元表, BlkObj为对象时返回vl对象表
- (defun K:GetAllObj4Blk (BlkEN / ObjFlag Lst en XX)
- (if (null vlax-dump-object) (vl-load-com));;将Visual LISP扩展功能加载到AutoLISP
- (setq ObjFlag Nil Lst nil)
- (if (eq (type BlkEN) 'VLA-OBJECT)
- (setq ObjFlag T
- BlkEN (vlax-vla-object->ename BlkEN)
- )
- )
- (setq en (tblobjname "block" (cdr (assoc 2 (entget BlkEN)))))
- (while (setq en (entnext en)) (setq Lst (cons en Lst)));收集块内图元
-
- (if ObjFlag (mapcar 'vlax-ename->vla-object Lst) Lst)
- )
用法:
- (K:GetAllObj4Blk (car (entsel)))
- (K:GetAllObj4Blk (vlax-ename->vla-object (car (entsel))))
|