明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 740|回复: 8

拆掉找不到文件的参照

[复制链接]
发表于 2023-2-19 13:07 | 显示全部楼层 |阅读模式
本帖最后由 sandyvs 于 2023-2-21 17:35 编辑

应该算是解决了吧,不过之前应该清理一下。最开始总是不成功,后来才发现参照的文件有多重参照
感谢@vitalgg !!


发表于 2023-2-19 21:00 | 显示全部楼层
本帖最后由 vitalgg 于 2023-2-21 18:21 编辑

  1. (foreach xref (block:list-xref-objs)
  2.   (if (and (setq path (vla-get-Path xref))
  3.            (/= "" path)
  4.            (null (findfile path)))
  5.       (vla-detach xref)
  6.   ))


查询文件是否存在 应该是 findfile 。

函数:block:list-xref-objs 源码见:
https://atlisp.cn/function/block:list-xref-objs

 楼主| 发表于 2023-2-19 22:39 | 显示全部楼层
vitalgg 发表于 2023-2-19 21:00
函数:block:list-xref-objs 源码见:
https://atlisp.cn/function/block:list-xref-objs

感谢回复!其实主要现在对lisp连入门也算不上,只是搜索自己想要的功能,进行一些简单的修改。我知道思路应该是判断参照路径存在不存在,如果不存在就拆离。只是不会用编程表达出来,先慢慢研究研究,要学习的还很多。。
 楼主| 发表于 2023-2-21 17:15 来自手机 | 显示全部楼层
本帖最后由 sandyvs 于 2023-2-21 17:16 编辑

(defun c:tt()
(setq xref (ssget "X" (list '(0 . "INSERT")   )))
(foreach xref (block:list-xref-objs)
  (if (and (setq path (vla-get-Path xref))
           (/= "" path)
           (null (findfile path)))
         
      (vla-detach xref)
  ))
  )


是这个意思不?我说没找到find函数。。

发表于 2023-2-21 18:20 | 显示全部楼层
sandyvs 发表于 2023-2-21 17:15
(defun c:tt()
(setq xref (ssget "X" (list '(0 . "INSERT")   )))
(foreach xref (block:list-xref-o ...

你是对的,应该是 findfile
发表于 2023-3-14 21:01 | 显示全部楼层
sandyvs 发表于 2023-2-21 17:15
(defun c:tt()
(setq xref (ssget "X" (list '(0 . "INSERT")   )))
(foreach xref (block:list-xref-o ...

问下 *blks*  在哪里??
发表于 2023-3-14 21:07 | 显示全部楼层
sandyvs 发表于 2023-2-21 17:15
(defun c:tt()
(setq xref (ssget "X" (list '(0 . "INSERT")   )))
(foreach xref (block:list-xref-o ...
  1. (defun c:Detachall nil (hlj:Detachall nil))
  2. (defun c:DetachNotExist nil (hlj:Detachall t))

  3.       (vl-load-com)
  4.       (defun *error* (msg)
  5.         (mip:layer-status-restore)
  6.         (princ msg)
  7.         (princ)
  8.       ) ;_ end of defun
  9. ;;-------------=={ Relative Path to Full Path }==-------------;;
  10. ;;                                                            ;;
  11. ;;  Converts a Relative XRef path to a Full Path.             ;;
  12. ;;------------------------------------------------------------;;
  13. ;;------------------------------------------------------------;;
  14. ;;  Arguments:                                                ;;
  15. ;;  dir  - Directory of the Drawing in which the Xref resides ;;
  16. ;;  path - Relative Xref Path                                 ;;
  17. ;;------------------------------------------------------------;;
  18. ;;  Returns:  Full XRef Path                                  ;;
  19. ;;------------------------------------------------------------;;
  20.        
  21.         ;;-------------=={完整路径的相对路径}==--------------;;

  22. ;; ;;

  23. ;; 将“相对外部参照”路径转换为“完整路径”;;

  24. ;;------------------------------------------------------------;;

  25. ;;------------------------------------------------------------;;

  26. ;; 参数:;;

  27. ;; dir-外部参照所在图形的目录;;

  28. ;; path-相对外部参照路径;;

  29. ;;------------------------------------------------------------;;

  30. ;; 返回:完整外部参照路径;;

  31. ;;------------------------------------------------------------;;
  32.        

  33. (defun LM:XRef:Relative->Full (dir path)
  34.     (setq dir (vl-string-right-trim "\" dir))
  35.     (cond
  36.         (   (eq ".." (substr path 1 2))
  37.             (LM:XRef:Relative->Full
  38.                 (substr dir 1 (vl-string-position 92 dir nil t))
  39.                 (substr path 4)
  40.             )
  41.         )
  42.         (   (eq "." (substr path 1 1))
  43.             (strcat dir (substr path 2))
  44.         )
  45.         (   (strcat dir "\" path))
  46.     )
  47. )
  48. ;;-------------=={ Full Path to Relative Path }==-------------;;
  49. ;;                                                            ;;
  50. ;;  Converts a Full XRef path to a Relative Path.             ;;
  51. ;;------------------------------------------------------------;;
  52. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  53. ;;------------------------------------------------------------;;
  54. ;;  Arguments:                                                ;;
  55. ;;  dir  - Directory of the Drawing in which the Xref resides ;;
  56. ;;  path - Full Xref Path                                     ;;
  57. ;;------------------------------------------------------------;;
  58. ;;  Returns:  Relative XRef Path                              ;;
  59. ;;------------------------------------------------------------;;

  60. ;(defun LM:XRef:Full->Relative ( dir path / p q )
  61. ;    (setq dir (vl-string-right-trim "\" dir))
  62. ;    (cond
  63. ;        (   (and
  64. ;                (setq p (vl-string-position 58  dir))
  65. ;                (setq q (vl-string-position 58 path))
  66. ;                (not (eq (strcase (substr dir 1 p)) (strcase (substr path 1 q))))
  67. ;            )
  68. ;            path
  69. ;        )
  70. ;        (   (and
  71. ;                (setq p (vl-string-position 92  dir))
  72. ;                (setq q (vl-string-position 92 path))
  73. ;                (eq (strcase (substr dir 1 p)) (strcase (substr path 1 q)))
  74. ;            )
  75. ;            (LM:Xref:Full->Relative (substr dir (+ 2 p)) (substr path (+ 2 q)))
  76. ;        )
  77. ;        (   (and
  78. ;                (setq q (vl-string-position 92 path))
  79. ;                (eq (strcase dir) (strcase (substr path 1 q)))
  80. ;            )
  81. ;            (strcat ".\" (substr path (+ 2 q)))
  82. ;        )
  83. ;        (   (eq "" dir)
  84. ;            path
  85. ;        )
  86. ;        (   (setq p (vl-string-position 92 dir))
  87. ;            (LM:Xref:Full->Relative (substr dir (+ 2 p)) (strcat "..\" path))
  88. ;        )
  89. ;        (   (LM:Xref:Full->Relative "" (strcat "..\" path)))
  90. ;    )
  91. ;)
  92.       (defun mip:layer-status-restore ( /  item)
  93.         (foreach item *PD_LAYER_LST*
  94.           (if (not (vlax-erased-p (car item)))
  95.             (vl-catch-all-apply
  96.               '(lambda ()
  97.                  (vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))
  98.                  (vla-put-freeze
  99.                    (car item)
  100.                    (cdr (assoc "freeze" (cdr item)))
  101.                  ) ;_ end of vla-put-freeze
  102.                ) ;_ end of lambda
  103.             ) ;_ end of vl-catch-all-apply
  104.           ) ;_ end of if
  105.         ) ;_ end of foreach
  106.         (setq *PD_LAYER_LST* nil)
  107.       ) ;_ end of defun
  108.       (defun mip:layer-status-save ( /  item)
  109.         (setq *PD_LAYER_LST* nil)
  110.         (vlax-for item (vla-get-layers
  111.                          (vla-get-activedocument (vlax-get-acad-object))
  112.                        ) ;_ end of vla-get-layers
  113.           (setq *PD_LAYER_LST*
  114.                  (cons (list item
  115.                              (cons "freeze" (vla-get-freeze item))
  116.                              (cons "lock" (vla-get-lock item))
  117.                        ) ;_ end of cons
  118.                        *PD_LAYER_LST*
  119.                  ) ;_ end of cons
  120.           ) ;_ end of setq
  121.           (vla-put-lock item :vlax-false)
  122.           (if (= (vla-get-freeze item) :vlax-true)
  123.             (vl-catch-all-apply
  124.               '(lambda () (vla-put-freeze item :vlax-false))
  125.             ) ;_ end of vl-catch-all-apply
  126.           ) ;_ end of if
  127.         ) ;_ end of vlax-for
  128.       ) ;_ end of defun
  129.       (defun delete-xref-img-underlay (exclude / blk count obj txt)
  130.         (mip:layer-status-save)
  131.         (vlax-for Blk (vla-get-Blocks
  132.                         (vla-get-activedocument (vlax-get-acad-object))
  133.                       ) ;_ end of vla-get-Blocks
  134.           (if (and (= (vla-get-IsXref Blk) :vlax-false)
  135.                    (not (wcmatch (vla-get-name Blk) "*|*"))
  136.               ) ;_ end of and
  137.             (progn
  138.               (setq        count 0
  139.                     txt   (strcat " Erase Xref and Underlay in "
  140.                                   (vla-get-name Blk)
  141.                           ) ;_ end of strcat
  142.               ) ;_ end of setq
  143.               (grtext -1 txt)
  144.               (vlax-for Obj        Blk
  145.                 (setq count (1+ count))
  146.                 (if        (zerop (rem count 10))
  147.                   (grtext -1 (strcat txt " : " (itoa count)))
  148.                 ) ;_ end of if
  149.                 (if
  150.                   (and (vlax-write-enabled-p Obj)
  151.                        (or
  152.                          (and ;_ XREF
  153.                            (= (vla-get-ObjectName obj) "AcDbBlockReference")
  154.                            (vlax-property-available-p Obj "Path")
  155.                            (not(and exclude (findfile(LM:XRef:Relative->Full (getvar "DWGPREFIX") (Vlax-Get Obj 'Path )))))
  156.                          ) ;_ end of and
  157.                          (and ;_ UNDERLAY
  158.                            (wcmatch (vla-get-ObjectName obj) "*Reference")
  159.                            (vlax-property-available-p Obj "UnderlayName")
  160.                          ) ;_ end of and
  161.                          (= (vla-get-ObjectName obj) "AcDbRasterImage") ;_ IMAGE
  162.                        ) ;_ end of or
  163.                   ) ;_ end of and
  164.                    (VL-CATCH-ALL-APPLY 'vla-Delete (list Obj))
  165.                 ) ;_ end of if
  166.               ) ;_ end of vlax-for
  167.             ) ;_ end of progn
  168.           ) ;_ end of if
  169.         ) ;_ end of vlax-for
  170.         (mip:layer-status-restore)
  171.       ) ;_ end of defun
  172.       (defun delete-all-dict (dict)
  173.     ;;; dict - dict name (like "ACAD_IMAGE_DICT", "ACAD_PDFDEFINITIONS" ... )
  174.         (vl-catch-all-apply
  175.           '(lambda ()
  176.              (vlax-map-Collection
  177.                (vla-item
  178.                  (vla-get-dictionaries
  179.                    (vla-get-activedocument (vlax-get-acad-object))
  180.                  ) ;_ end of vla-get-dictionaries
  181.                  dict ;_ "ACAD_IMAGE_DICT"
  182.                ) ;_ end of vla-Item
  183.                'vla-delete
  184.              ) ;_ end of vlax-map-Collection
  185.            ) ;_ end of lambda
  186.         ) ;_ end of vl-catch-all-apply
  187.       ) ;_ end of defun

  188. (defun hlj:Detachall (exclude /)
  189.       (vl-load-com)
  190.       (delete-xref-img-underlay exclude)
  191.       (command "_-xref" "_d" "*")
  192.       (while (> (getvar "CMDACTIVE") 0) (command))
  193.       (mapcar 'delete-all-dict
  194.               (list        "ACAD_IMAGE_DICT"
  195.                     "ACAD_PDFDEFINITIONS"
  196.                     "ACAD_DWFDEFINITIONS"
  197.                     "ACAD_DGNDEFINITIONS"
  198.                     "ACAD_DATALINK"
  199.               ) ;_ end of list
  200.       ) ;_ end of mapcar
  201.       (command "_.regenall")
  202.       (command "_.externalreferences")
  203.       (princ)
  204.     ) ;_ end of defun


  205. ;(defun block:list-xref-objs (/ res)
  206. ;  ;"获取外部参照对象列表"
  207. ;  ;"外部参照对象列表"
  208. ;  ;""
  209. ;  (setq res nil)
  210. ;  (vlax-for blk *blks* (if (= :vlax-true (vla-get-isxref blk))
  211. ;      (setq res (cons blk res))))
  212. ;  res)

记得你是不是发过这个,,感觉很牛的样子,,我瞎研究了好几次,奈何自己没半点什么面向对象的编程能力,不知有没有大佬给看看,,调教下??功能就是要删除已经卸载的外部参照,好像不管怎么设置都是删除全部。。。有侵权的联系删除,,谢谢!!
 楼主| 发表于 2023-3-14 23:22 | 显示全部楼层
yaojing38 发表于 2023-3-14 21:07
记得你是不是发过这个,,感觉很牛的样子,,我瞎研究了好几次,奈何自己没半点什么面向对象的编程能力 ...

不好使,所以不用这个了,缺的函数,2楼网址有
发表于 2023-3-15 09:58 | 显示全部楼层
sandyvs 发表于 2023-3-14 23:22
不好使,所以不用这个了,缺的函数,2楼网址有

已卸载的不能删除是吧??主键重复 位置,是什么东西??
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-19 10:39 , Processed in 0.169246 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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