- 积分
- 674
- 明经币
- 个
- 注册时间
- 2006-12-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
正常情况下,画图时图块分解后,图块所包含的图元都会变到0层,但有时我们更希望它们能被分解到当前层,为了达到这个目的,写了下面的代码.
;将块分解到当前层
(defun jc-explode-block-clayer (blk / obj_blk array_obj obj err)
(setq obj_blk (vlax-ename->vla-object blk))
;只分解块
(if (= (vla-get-objectname obj_blk) "AcDbBlockReference")
(progn
;错误处理,跳过那些不能被分解的块
;vla-explode产生一个包含块内实体的数组
(setq err (vl-catch-all-apply '(lambda () (setq array_obj (vla-explode obj_blk)))))
(if (not (vl-catch-all-error-p err))
(progn
(vla-delete obj_blk)
(setq array_obj (vlax-variant-value array_obj))
(setq array_obj (vlax-safearray->list array_obj))
(foreach obj array_obj
(vla-put-layer obj (getvar "clayer"))
)
)
)
)
)
)
;调用例程
(defun c:eb ( / ssel count i)
(setq ssel (ssget))
(if (/= ssel nil)
(progn
(setq count (sslength ssel))
(setq i 0)
(repeat count
(jc-explode-block-clayer (ssname ssel i))
(setq i (1+ i))
)
)
)
(princ)
)
|
|