本帖最后由 kucha007 于 2022-10-28 00:02 编辑
正好最近在学习Visual Lisp,练习一下~
- (defun C:B2L (/ Doc LayLst Old_Cmd Lst1)
- (vl-load-com)
- (setq Old_Cmd (getvar "cmdecho"))(setvar "cmdecho" 0)
- (setq Doc (vla-get-ActiveDocument (vlax-get-acad-object))
- LayLst (vla-get-layers Doc)
- )
- (vla-startundomark Doc) ;记录编组
- (vlax-for e LayLst
- (if (= (vla-get-lock e) :vlax-true)
- (progn
- (setq LokLst (cons (vla-get-name e) LokLst))
- (vla-put-lock e :vlax-false)
- )
- )
- );临时解锁图层
- (setq Lst1 nil)
- (vlax-for blk (vla-get-blocks Doc)
- (vlax-for obj blk
- (if (= (vla-get-objectname obj) "AcDbBlockReference")
- (setq Lst1 (cons obj Lst1))
- )
- )
- (if Lst1 (foreach obj Lst1 (vla-put-layer obj "0")))
- )
- (if LokLst ;恢复图层状态
- (foreach e LokLst
- (vla-put-lock (vla-item LayLst e) :vlax-true)
- (setq LokLst nil)
- )
- )
- ;(vla-regen Doc :vlax-true)
- (vla-endundomark Doc) ;结束编组
- (princ "\n——★★★ 图块已移动到0图层 ★★★——")
- (command "redraw")(setvar "cmdecho" Old_Cmd)(princ)
- )
|