明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1649|回复: 4

[源码] 求rename命令增强版

[复制链接]
发表于 2013-10-30 20:54 | 显示全部楼层 |阅读模式
100明经币
本帖最后由 weiqi 于 2013-11-2 22:31 编辑

求在一个DWG图里,rename命令增加版,把图层,块名,标注样式等。。。一个命令全部加上前缀。

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2015-1-3 13:12 | 显示全部楼层
这个我也需要
回复

使用道具 举报

 楼主| 发表于 2018-11-9 22:58 | 显示全部楼层
自己解决多年~
回复

使用道具 举报

发表于 2023-7-3 11:29 | 显示全部楼层
产品图导入时,一直都是手动改,可以分享吗
回复

使用道具 举报

发表于 2023-7-4 14:00 | 显示全部楼层
本帖最后由 andyding 于 2023-7-4 16:10 编辑

所有通用函数来自论坛,非本人原创。搬运拼凑而成,试试看能不能用吧。

  1. (defun C:renall  (/ BLOCKLST blockna DIMLST I LAYERLST M N P PRE TEXTLST)
  2.   (command "_undo" "be")
  3.   (setq *ACAD*  (vlax-get-acad-object)
  4.         *DOC*   (vla-get-ActiveDocument *ACAD*)
  5.   )
  6.   (if (and
  7.   (setq blocklst (MJ:blocks))
  8.   (setq layerlst (MJ:layers))
  9.   (setq textlst (MJ:textstyles))
  10.   (setq dimlst (MJ:dimstyles))
  11.       )
  12.     (progn
  13.       (setq i 0
  14.       n 0
  15.       m 0
  16.       P 0
  17.       )
  18.       (setq pre (getstring "\n请输入前缀:"))
  19.       (repeat (length blocklst)
  20.   (if (= (substr (nth i blocklst) 1 1) "*")
  21.     (setq blockna (substr (nth i blocklst) 2))
  22.     (setq blockna (nth i blocklst))
  23.   )
  24.   (MJ:RenameBlock1
  25.     (nth i blocklst)
  26.     (strcat pre blockna)
  27.   )
  28.   (setq i (1+ i))
  29.       )
  30.       (repeat (length layerlst)
  31.   (if (/= (nth n layerlst) "0")
  32.     (progn
  33.       (MJ:Renamelayer1
  34.         (nth n layerlst)
  35.         (strcat pre (nth n layerlst))
  36.       )
  37.       (setq n (1+ n))
  38.     )
  39.     (setq n (1+ n))
  40.   )
  41.       )
  42.       (repeat (length textlst)
  43.   (command "_.rename"
  44.      "s"
  45.      (nth m textlst)
  46.      (strcat pre (nth m textlst))
  47.   )
  48.   (setq m (1+ m))
  49.       )
  50.       (repeat (length dimlst)
  51.   (MJ:RenameDimStyles1
  52.     (nth p dimlst)
  53.     (strcat pre (nth p dimlst))
  54.   )
  55.   (setq p (1+ p))
  56.       )
  57.       (vla-auditinfo
  58.   (vla-get-activedocument (vlax-get-acad-object))
  59.   :vlax-true
  60.       )
  61.     )
  62.   )
  63.   (command "_undo" "end")
  64.   (princ)
  65. )

  66. ;;改块名,bn的块存在,名为nn的块不存在
  67. ;;(MJ:RenameBlock1 "ccd1" "ccd2")
  68. (defun MJ:RenameBlock1 (bn nn /)
  69.   (vla-put-name (vla-item (vla-get-blocks *DOC*) bn) nn)
  70. )
  71. ;;改层名
  72. (defun MJ:Renamelayer1 (bn nn /)
  73.   (vla-put-name (vla-item (vla-get-layers *DOC*) bn) nn)
  74. )
  75. ;;改字体样式名
  76. (defun MJ:RenameDimStyles1 (bn nn /)
  77.   (vla-put-name (vla-item (vla-get-DimStyles *DOC*) bn) nn)
  78. )


  79. ;; 返回块名列表("*D5" "A$C263E5435" "b2" "b1")
  80. (defun MJ:blocks (/ b bn tl)
  81.   (vlax-for b (vla-get-blocks *DOC*)
  82.     (if  (= (vla-get-islayout b) :vlax-false)
  83.       (setq tl (cons (vla-get-name b) tl))
  84.     )
  85.   )
  86.   (reverse tl)
  87. )
  88. ;; 返回层名列表
  89. (defun MJ:layers (/ b bn tl)
  90.   (vlax-for b (vla-get-layers *DOC*)
  91.     (setq tl (cons (vla-get-name b) tl))
  92.   )
  93.   (reverse tl)
  94. )

  95. ;; 返回字体样式名列表
  96. (defun MJ:textstyles (/ b bn tl)
  97.   (vlax-for b (vla-get-textstyles *DOC*)
  98.     (setq tl (cons (vla-get-name b) tl))
  99.   )
  100.   (reverse tl)
  101. )
  102. ;; 返回标注样式列表
  103. (defun MJ:dimstyles (/ b bn tl)
  104.   (vlax-for b (vla-get-DimStyles *DOC*)
  105.     (setq tl (cons (vla-get-name b) tl))
  106.   )
  107.   (reverse tl)
  108. )


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-25 21:42 , Processed in 1.759896 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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