明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 563|回复: 11

[源码] 急需识别多个字符的拆除外部参照语句

[复制链接]
发表于 2021-6-2 09:13 | 显示全部楼层 |阅读模式
5明经币
想卸载除了带有“结构参照”、“建筑参照”、“设备参照”的外部参照

(Defun C:dxrs ( )         
        (setvar "cmdecho" 0)           
        (command "-xref" "Detach" "~结构参照*")
          (princ)
)
(Defun C:gxrs ( )         
        (setvar "cmdecho" 0)              
        (command "-xref" "unload" "~结构参照*")
          (princ)
);■■■■

最佳答案

发表于 2021-6-2 09:13 | 显示全部楼层
  1. (defun getxrefnames (/ BLKS I NAME XREFNAMES)
  2.   (setq        blks (vla-get-blocks
  3.                (vla-get-ActiveDocument (VLAX-GET-ACAD-OBJECT))
  4.              )
  5.   )
  6.   (setq xrefnames '())
  7.   (vlax-for item blks
  8.     (setq name (vla-get-name item))
  9.     (if        (and (setq i (VL-STRING-SEARCH "|" name))
  10.              (/= (substr name 1 1) "*")
  11.              (setq name (substr name 1 i))
  12.              (not (member name xrefnames))
  13.         )
  14.       (setq xrefnames (cons name xrefnames))
  15.     )
  16.   )
  17.   xrefnames
  18. )

  19. (defun Detach-xrefs (names / )
  20.   (foreach item names
  21.     (if (member item (getxrefnames))
  22.       (command "-xref" "Detach" item)
  23.       )
  24.     )
  25.   t
  26.   )

  27. (defun unload-xrefs (names / )
  28.   (foreach item names
  29.     (if (member item (getxrefnames))
  30.       (command "-xref" "unload" item)
  31.       )
  32.     )
  33.   t
  34.   )
回复

使用道具 举报

发表于 2021-6-2 10:05 | 显示全部楼层
试一下行不行
  (command "-xref" "Detach" "*结构参照*")
回复

使用道具 举报

 楼主| 发表于 2021-6-2 11:16 | 显示全部楼层

具体要把我想要的关键字“结构参照”“建筑参照”放在哪里呢?
回复

使用道具 举报

 楼主| 发表于 2021-6-2 11:18 | 显示全部楼层
start4444 发表于 2021-6-2 10:05
试一下行不行
  (command "-xref" "Detach" "*结构参照*")

我想同时屏蔽 结构参照 、建筑参照
回复

使用道具 举报

发表于 2021-6-2 11:26 | 显示全部楼层
iamhuangjinming 发表于 2021-6-2 11:18
我想同时屏蔽 结构参照 、建筑参照

(command "-xref" "Detach" "*结构参照*")
(command "-xref" "Detach" "*建筑参照*")
要什么下面继续写就是了
回复

使用道具 举报

 楼主| 发表于 2021-6-2 11:37 | 显示全部楼层
start4444 发表于 2021-6-2 11:26
(command "-xref" "Detach" "*结构参照*")
(command "-xref" "Detach" "*建筑参照*")
要什么下面继续 ...

*~结构参照* 我想要带这个字符的,不要拆除,按你的,应该是拆掉了吧

点评

关键是字符,解决了你拆不拆都行啦,只是给个参考你  发表于 2021-6-2 11:41
回复

使用道具 举报

发表于 2021-6-2 15:05 | 显示全部楼层
  1. (defun remove (lst str / )
  2.   (vl-remove-if '(lambda(x)
  3.                        (VL-STRING-SEARCH str x)) lst)
  4.   )
  5. (defun remove-not (lst str / )
  6.   (vl-remove-if-not '(lambda(x)
  7.                        (VL-STRING-SEARCH str x)) lst)
  8.   )
  9. (defun removes (lst strs / )
  10.   (foreach item strs
  11.     (setq lst (remove lst item))
  12.     )
  13.   )
  14. (defun remove-nots (lst strs / )
  15.   (foreach item strs
  16.     (setq lst (remove-not lst item))
  17.     )
  18.   )


  19. _$ (setq lst '("123" "234" "345" "456" "567"))
  20. ("123" "234" "345" "456" "567")
  21. _$ (setq str "4")
  22. "4"
  23. _$ (remove lst str)
  24. ("123" "567")
  25. _$ (remove-not lst str)
  26. ("234" "345" "456")
  27. _$ (setq strs '("3" "4"))
  28. ("3" "4")
  29. _$ (removes lst strs)
  30. ("567")
  31. _$ (remove-nots lst strs)
  32. ("234" "345")
  33. _$
回复

使用道具 举报

 楼主| 发表于 2021-6-2 16:27 | 显示全部楼层

不会用呢。。 可以按提的需求整个直接能用的么。。。谢谢大佬~
回复

使用道具 举报

发表于 2021-6-3 09:07 | 显示全部楼层
本帖最后由 lijiao 于 2021-6-3 17:15 编辑

想卸载除了带有“结构参照”、“建筑参照”、“设备参照”的外部参照:
(unload-xrefs (removes (getxrefnames) '(“结构参照” “建筑参照” “设备参照”)))

想撤离除了带有“结构参照”、“建筑参照”、“设备参照”的外部参照:
(Detach-xrefs (removes (getxrefnames) '(“结构参照” “建筑参照” “设备参照”)))
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 01:40 , Processed in 0.177176 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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