找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 399|回复: 2

[每日一码] Detach图中引用或未载入的XREF

[复制链接]

已领礼包: 19个

财富等级: 恭喜发财

发表于 2017-5-4 16:54:33 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 Lisphk 于 2017-5-4 16:56 编辑

[Plain Text] 纯文本查看 复制代码
: [url=https://autocadtips1.com/2011/09/01/autolisp-detach-all-xrefs/]https://autocadtips1.com/2011/09/01/autolisp-detach-all-xrefs/[/url] author unknown
; (load "Detachall") Detachall ;
(defun C:Detachall (/ *error* mip:layer-status-restore mip:layer-status-save delete-xref-img-underlay delete-all-dict)

  (defun *error* (msg)
        (mip:layer-status-restore)
        (princ msg)
        (princ)
  ) ;_ end of defun

  (defun mip:layer-status-restore ()
        (foreach item *PD_LAYER_LST*
          (if (not (vlax-erased-p (car item)))
                (vl-catch-all-apply
                  '(lambda ()
                        (vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))
                        (vla-put-freeze
                          (car item)
                          (cdr (assoc "freeze" (cdr item)))
                        )
                  )
                )
          )
        )
        (setq *PD_LAYER_LST* nil)
  ) ;_ end of defun

  (defun mip:layer-status-save ()
        (setq *PD_LAYER_LST* nil)
        (vlax-for item (vla-get-layers(vla-get-activedocument (vlax-get-acad-object)))
          (setq *PD_LAYER_LST*
                (cons
                  (list item (cons "freeze" (vla-get-freeze item))(cons "lock" (vla-get-lock item)))
                  *PD_LAYER_LST*
                )
          )
          (vla-put-lock item :vlax-false)
          (if (= (vla-get-freeze item) :vlax-true)
                (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false)))
          )
        )
  ) ;_ end of defun

  (defun delete-xref-img-underlay (/ count txt BlkList)
        (mip:layer-status-save)

        (vlax-for Blk (vla-get-Blocks(vla-get-activedocument (vlax-get-acad-object)))
          (setq BlkList (entget(vlax-vla-object->ename Blk)))
          (if(and
                  (= (vla-get-IsXref Blk) :vlax-false)
                  (not (wcmatch (vla-get-name Blk) "*|*")
;                  (logand(assoc 70 BlkList)32)
;                  (not(logand(assoc 70 BlkList)32))
                ))
                (progn
                  (setq
                        count 0
                        txt (strcat " Erase Xref and Underlay in " (vla-get-name Blk))
                  )
                  (grtext -1 txt)
                  (vlax-for Obj Blk
                        (setq count (1+ count))
                        (if (zerop (rem count 10))(grtext -1 (strcat txt " : " (itoa count))))
                        (if
                          (and (vlax-write-enabled-p Obj)
                                (or
                                  (and ;_ XREF
                                        (= (vla-get-ObjectName obj) "AcDbBlockReference")
                                        (vlax-property-available-p Obj "Path")
;                  (logand(assoc 70 BlkList)32)
;                  (not(logand(assoc 70 BlkList)32))
                                  ) ;_ end of and
                                  (and ;_ UNDERLAY
                                        (wcmatch (vla-get-ObjectName obj) "*Reference")
                                        (vlax-property-available-p Obj "UnderlayName")
                                  ) ;_ end of and
                                  (= (vla-get-ObjectName obj) "AcDbRasterImage") ;_ IMAGE
                                ) ;_ end of or
                          ) ;_ end of and
                          (VL-CATCH-ALL-APPLY 'vla-Delete (list Obj))
                        ) ;_ end of if
                  ) ;_ end of vlax-for
                ) ;_ end of progn
          ) ;_ end of if
        ) ;_ end of vlax-for
        (mip:layer-status-restore)
  ) ;_ end of defun

  (defun delete-all-dict (dict)
        ;;; dict - dict name (like "ACAD_IMAGE_DICT", "ACAD_PDFDEFINITIONS" ... )
        (vl-catch-all-apply
          '(lambda ()
                (vlax-map-Collection
                  (vla-item(vla-get-dictionaries(vla-get-activedocument (vlax-get-acad-object)))dict)
                  'vla-delete
                ) ;_ end of vlax-map-Collection
          ) ;_ end of lambda
        ) ;_ end of vl-catch-all-apply
  ) ;_ end of defun

  (delete-xref-img-underlay)
  (command "_-xref" "_d" "*")
  (while (> (getvar "CMDACTIVE") 0) (command))
  (mapcar 'delete-all-dict (list "ACAD_IMAGE_DICT" "ACAD_PDFDEFINITIONS" "ACAD_DWFDEFINITIONS" "ACAD_DGNDEFINITIONS"))
  (command "_.regenall")
  (command "_.externalreferences")
  (princ)
) ;_ end of defun
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 6468个

财富等级: 富甲天下

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

使用道具 举报

已领礼包: 217个

财富等级: 日进斗金

发表于 2017-5-5 09:39:40 | 显示全部楼层
detach:拆离
作用是把所有外部参照拆掉,一个不剩。非常六
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-12 10:34 , Processed in 0.389372 second(s), 39 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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