找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 415|回复: 1

[每日一码] 修改XREF名字

[复制链接]

已领礼包: 19个

财富等级: 恭喜发财

发表于 2018-11-18 16:05:32 | 显示全部楼层 |阅读模式

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

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

×
  1. (defun c:xren ( / AT:ListSelect adoc bl bll xrl pthl pth xrn nam fullpth )

  2.   (vl-load-com)

  3.   (defun AT:ListSelect ( title label height width multi lst / fn fo d item f )
  4.     ;; List Select Dialog (Temp DCL list box selection, based on provided list)
  5.     ;; title - list box title
  6.     ;; label - label for list box
  7.     ;; height - height of box
  8.     ;; width - width of box
  9.     ;; multi - selection method ["true": multiple, "false": single]
  10.     ;; lst - list of strings to place in list box
  11.     ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
  12.     (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  13.     (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
  14.                      (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
  15.                      (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
  16.                      (strcat "width = " (vl-princ-to-string width) ";")
  17.                      (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
  18.                )
  19.       (write-line x fo)
  20.     )
  21.     (close fo)
  22.     (new_dialog "list_select" (setq d (load_dialog fn)))
  23.     (start_list "lst")
  24.     (mapcar (function add_list) lst)
  25.     (end_list)
  26.     (setq item (set_tile "lst" "0"))
  27.     (action_tile "lst" "(setq item $value)")
  28.     (setq f (start_dialog))
  29.     (unload_dialog d)
  30.     (vl-file-delete fn)
  31.     (if (= f 1)
  32.       (mapcar '(lambda ( n ) (nth n lst)) (read (strcat "(" item ")")))
  33.     )
  34.   )

  35.   (if (= 1 (getvar 'dwgtitled))
  36.     (progn
  37.       (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  38.       (while (setq bl (tblnext "BLOCK" (null bl)))
  39.         (setq bll (cons (cdr (assoc 2 bl)) bll))
  40.       )
  41.       (foreach bl bll
  42.         (if (= (vla-get-isxref (vla-item (vla-get-blocks adoc) bl)) :vlax-true)
  43.           (setq xrl (cons bl xrl))
  44.         )
  45.       )
  46.       (foreach xr xrl
  47.         (setq pthl (cons (vla-get-path (vla-item (vla-get-blocks adoc) xr)) pthl))
  48.       )
  49.       (if pthl
  50.         (progn
  51.           (while (null pth)
  52.             (setq pth (car (AT:ListSelect "RENAME XREF" "Select Xref to rename:" 25 50 "false" pthl)))
  53.           )
  54.           (setq xrn (vl-filename-base pth))
  55.           (setq nam (car xrl))
  56.           (while (tblsearch "BLOCK" nam)
  57.             (if (/= nam (car xrl))
  58.               (alert "Specified filename already exist in DWG blocks database... Please specify different filename...")
  59.             )
  60.             (setq nam (lisped "TYPE NEW FILENAME WITHOUT EXTENSION"))
  61.           )
  62.           (if (= "." (substr pth 1 1))
  63.             (setq fullpth (strcat (getvar 'dwgprefix) (substr pth 3)))
  64.           )
  65.           (if fullpth
  66.             (vl-file-copy fullpth (strcat (vl-filename-directory fullpth) "\\" nam ".dwg"))
  67.             (vl-file-copy pth (strcat (vl-filename-directory pth) "\\" nam ".dwg"))
  68.           )
  69.           (vl-cmdf "_.-XREF" "_P" xrn (if fullpth (strcat (vl-string-right-trim (strcat (vl-filename-base pth) ".dwg") pth) nam ".dwg") (strcat (vl-filename-directory pth) "\\" nam ".dwg")))
  70.           (vl-cmdf "_.-RENAME" "_B" xrn nam)
  71.           (if fullpth
  72.             (vl-file-delete fullpth)
  73.             (vl-file-delete pth)
  74.           )
  75.         )
  76.         (prompt "\nDWG don't have XREF entities attached...")
  77.       )
  78.     )
  79.     (alert "DWG isn't saved yet... Save DWG and restart routine again...")
  80.   )
  81.   (princ)
  82. )
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 6468个

财富等级: 富甲天下

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 13:50 , Processed in 0.160071 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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