明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2340|回复: 9

求cad文字内斜杠/前后的字符互换

[复制链接]
发表于 2014-9-4 13:19:09 | 显示全部楼层 |阅读模式
5明经币
所有选中的文字,斜杠前后的字符互换,且斜杠前的互换范围不超过空格,比如将6D25 4/2改为6D25 2/4
结构底板梁配筋经常用到。 以前见过这样的程序,论坛上找了好久没找到,请大家帮忙。

最佳答案

发表于 2014-9-4 13:19:10 | 显示全部楼层
  1. (vl-load-com)
  2. (defun c:test1 (/ ss n lst str)
  3.   (defun wkgcl (str / lst)
  4.     (while (vl-string-search "/" str)
  5.       (setq str (vl-string-subst """" "/" str))
  6.     )
  7.     (setq str (strcat "("" str "")"))
  8.     (setq lst (read str)
  9.           lst (reverse lst)
  10.     )
  11.     (setq lst (mapcar '(lambda (x) (strcat x "/")) lst))
  12.     (setq str (vl-string-right-trim "/" (apply 'strcat lst)))
  13.   )
  14.   (defun ykgcl (str / len i str1 str2)
  15.     (setq len  (strlen str)
  16.           i    (vl-string-search " " str)
  17.           str1 (substr str 1 (1+ i))
  18.           str2 (substr str (+ i 2))
  19.     )
  20.     (setq str (strcat str1 (wkgcl str2)))
  21.   )
  22.   (setq ss (ssget '((0 . "text"))))
  23.   (repeat (setq N (sslength ss))
  24.     (setq LST (cons (ssname SS (setq N (1- N))) LST))
  25.   )
  26.   (mapcar
  27.     '(lambda (en)
  28.        (setq ent (entget en)
  29.              str (cdr (assoc 1 ent))
  30.        )
  31.        (if (and (vl-string-search "/" str) (vl-string-search " " str))
  32.          (entmod (subst (cons 1 (ykgcl str)) (assoc 1 ent) ent))
  33.          (if (vl-string-search "/" str)
  34.            (entmod (subst (cons 1 (wkgcl str)) (assoc 1 ent) ent))
  35.          )
  36.        )
  37.      )
  38.     lst
  39.   )
  40.   (princ)
  41. )
试试这个
回复

使用道具 举报

发表于 2014-9-5 10:20:16 | 显示全部楼层
本帖最后由 夏生生 于 2014-9-5 10:32 编辑
  1. (defun c:test1 (/ en ent str n len i str1 str2)
  2.   (while (and (setq en (car (entsel)))
  3.               (= "TEXT" (cdr (assoc 0 (setq ent (entget en)))))
  4.               (setq n (vl-string-search "/" (setq str (cdr (assoc 1 ent)))))
  5.          )
  6.     (setq len  (strlen str)
  7.           i    (vl-string-search " " str)
  8.           str1 (substr str (+ n 2))
  9.           str2 (substr str (+ i 2) (- n i 1))
  10.           str (strcat (substr str 1 i) " " str1 "/" str2)
  11.     )
  12.     (entmod (subst(cons 1 str)(assoc 1 ent) ent))
  13.   )
  14. )
对于两排以上,由于一般来讲仅第一或最后一排不同,故本程序亦可处理,对于第一排移至最后一排点一次,对于最后一排移至第一排点排数次
回复

使用道具 举报

 楼主| 发表于 2014-9-5 20:54:57 | 显示全部楼层
运行了一下程序,这里还有几个问题。
1.程序中斜杠前后没数字就不起效果,能不能调整为不管斜杠前后是什么都互换,
   即不仅能将6D25 4/2改为6D25 2/4,也能将6D25/2D22变为2D22/6D25
2.能不能满足一次选择无论几排钢筋都能互换,比如6D25/6D22/2D22改为2D22/6D22/6D25
3.程序只能选择一个改一个,能不能框选后全部修改?
回复

使用道具 举报

发表于 2014-9-6 07:30:14 | 显示全部楼层
1981yyzz 发表于 2014-9-5 20:54
运行了一下程序,这里还有几个问题。
1.程序中斜杠前后没数字就不起效果,能不能调整为不管斜杠前后是什么 ...

如果有3个/怎么调换...??
回复

使用道具 举报

发表于 2014-9-7 09:39:08 | 显示全部楼层
前面写那个原理都有了,步骤也比较清晰,自己稍微修改一下就行
回复

使用道具 举报

发表于 2014-9-8 06:54:53 | 显示全部楼层
  1. (defun AYL-DivideString  (Str Sep / Sub Lst)
  2.   (setq Sub "")
  3.   (while (= (substr Str 1 1) Sep)
  4.     (setq Sub (strcat Sub Sep))
  5.     (setq Str (substr Str 2))
  6.   )
  7.   (if (= Sub "")
  8.     (setq Lst nil)
  9.     (setq Lst (list Sub))
  10.   )
  11.   (while (setq val (vl-string-search Sep Str))
  12.     (setq Lst (cons (substr Str 1 Val) Lst))
  13.     (setq Str (substr Str (1+ Val)))
  14.     (setq Sub "")
  15.     (while (= (substr Str 1 1) Sep)
  16.       (setq Sub (strcat Sub Sep))
  17.       (setq Str (substr Str 2))
  18.     )
  19.     (setq Lst (cons Sub Lst))
  20.   )
  21.   (or (= Str "") (setq Lst (cons Str Lst)))
  22.   Lst
  23. )

  24. (defun AYL-ssClist (ss / EnLst n)
  25.   (setq EnLst nil)
  26.   (repeat (setq n (sslength ss))
  27.     (setq EnLst (cons (ssname ss (setq n (1- n))) EnLst))
  28.   )
  29. )

  30. (defun AYL-FixedString (Str / Lst1 Lst2)
  31.   (setq Lst0 (AYL-DivideString Str " ") Lst1 nil)
  32.   (while (setq Item (car Lst0))
  33.     (setq Lst0 (cdr Lst0))
  34.     (setq Lst2 (AYL-DivideString Item "/"))
  35.     (setq Lst1 (append Lst2 Lst1))
  36.   )
  37.   (apply 'strcat Lst1)
  38. )
  39. ;|
  40. (defun c:test (/ en ent str)
  41.   (while (setq en (car (entsel)))
  42.     (and (= "TEXT" (cdr (assoc 0 (setq ent (entget en)))))
  43.    (setq str (AYL-FixedString (cdr (assoc 1 ent))))
  44.    (entmod (subst (cons 1 str) (assoc 1 ent) ent))
  45.     )
  46.   )
  47.   (princ)
  48. )
  49. |;
  50. (defun c:tt (/ EntLst)
  51.   (if (setq ss (ssget '((0 . "*Text"))))
  52.     (progn
  53.       (setq EntLst (AYL-ssClist ss)
  54.       ss     nil
  55.       )
  56.       (mapcar
  57.   (function
  58.     (lambda (x / a b)
  59.       (setq a (entget x)
  60.       b (assoc 1 a)
  61.       )
  62.       (entmod (subst (cons 1 (AYL-FixedString (cdr b))) b a))
  63.     )
  64.   )
  65.   EntLst
  66.       )
  67.     )
  68.   )
  69.   (princ)
  70. )

评分

参与人数 1明经币 +1 金钱 +20 收起 理由
1981yyzz + 1 + 20 赞一个!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2014-9-10 06:58:15 | 显示全部楼层
感谢夏生生和nzl1116两位前辈的解答。
回复

使用道具 举报

发表于 2023-4-29 00:04:26 | 显示全部楼层
留个脚印,记录下。后续可能用得到
回复

使用道具 举报

发表于 2023-10-11 15:27:48 | 显示全部楼层
感谢nzl1116大师的源码,为您点赞!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-27 08:40 , Processed in 0.190530 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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