乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 96|回复: 1

[编程交流] 批处理文本编辑器

[复制链接]

25

主题

61

帖子

38

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
130
发表于 2022-7-6 12:30:35 | 显示全部楼层 |阅读模式
大家好,
 
我有一个旧的lisp路径,它将更改高度/旋转/样式/文本单个和全局编辑器,但我更感兴趣的是使用单个和全局编辑文本,但我的问题是,这将不适用于多行文字,只适用于Dtext,有什么可以帮我修复此lsp以处理多行文字,或者如果您有任何lsp路径,它将全局编辑或单个,它将选择所有文本,请提供给我
 
  1. ;;;
  2. ;;; Change the text of an entity.
  3. ;;;
  4. (defun cht_te ()
  5. (setq sslen (sslength sset))
  6. (initget "Globally Individually Retype")
  7. (setq ans (getkword
  8.    "\nSearch and replace text.  Individually/Retype/<Globally>:"))
  9. (setq cht_ot (getvar "texteval"))
  10. (setvar "texteval" 1)
  11. (cond
  12.    ((= ans "Individually")
  13.      (if (= (getvar "popups") 1)
  14.        (progn
  15.          (initget "Yes No")
  16.          (setq ans (getkword "\nEdit text in dialogue? <Yes>:"))
  17.        )
  18.        (setq ans "No")
  19.      )
  20.      (while (> sslen 0)
  21.        (redraw (setq sn (ssname sset (setq sslen (1- sslen)))) 3)
  22.        (setq ss (ssadd))
  23.        (ssadd (ssname sset sslen) ss)
  24.        (if (= ans "No")
  25.          (chgtext ss)
  26.          (command "_.DDEDIT" sn "")
  27.        )
  28.        (redraw sn 1)
  29.      )
  30.    )
  31.    ((= ans "Retype")
  32.      (while (> sslen 0)
  33.        (setq ent (entget(ssname sset (setq sslen (1- sslen)))))
  34.        (redraw (cdr(assoc -1 ent)) 3)
  35.        (prompt (strcat "\nOld text: " (cdr(assoc 1 ent))))
  36.        (setq nt (getstring  T "\nNew text: "))
  37.        (redraw (cdr(assoc -1 ent)) 1)
  38.        (if (> (strlen nt) 0)
  39.          (entmod (subst (cons 1 nt) (assoc 1 ent) ent))
  40.        )
  41.      )
  42.    )
  43.    (T
  44.      (chgtext sset)                  ; Change 'em all
  45.    )
  46. )
  47. (setvar "texteval" cht_ot)
  48. )
  49. ;;;
  50. ;;; The old CHGTEXT command - rudimentary text editor
  51. ;;;
  52. ;;;
  53. (defun C:CHGTEXT () (chgtext nil))
  54. (defun chgtext (objs / last_o tot_o ent o_str n_str st s_temp
  55.                       n_slen o_slen si chf chm cont ans)
  56. (if (null objs)
  57.    (setq objs (ssget))               ; Select objects if running standalone
  58. )
  59. (setq chm 0)
  60. (if objs
  61.    (progn                   ; If any objects selected
  62.      (if (= (type objs) 'ENAME)
  63.        (progn
  64.          (setq ent (entget objs))
  65.          (princ (strcat "\nExisting string: " (cdr (assoc 1 ent))))
  66.        )
  67.        (if (= (sslength objs) 1)
  68.          (progn
  69.            (setq ent (entget (ssname objs 0)))
  70.            (princ (strcat "\nExisting string: " (cdr (assoc 1 ent))))
  71.          )
  72.        )
  73.      )
  74.      (setq o_str (getstring "\nMatch string   : " t))
  75.      (setq o_slen (strlen o_str))
  76.      (if (/= o_slen 0)
  77.        (progn
  78.          (setq n_str (getstring "\nNew string     : " t))
  79.          (setq n_slen (strlen n_str))
  80.          (setq last_o 0
  81.                tot_o  (if (= (type objs) 'ENAME)
  82.                         1
  83.                         (sslength objs)
  84.                       )
  85.          )
  86.          (while (< last_o tot_o)     ; For each selected object...
  87.            (if (= "TEXT"             ; Look for TEXT entity type (group 0)
  88.                   (cdr (assoc 0 (setq ent (entget (ssname objs last_o))))))
  89.              (progn
  90.                (setq chf nil si 1)
  91.                (setq s_temp (cdr (assoc 1 ent)))
  92.                (while (= o_slen (strlen (setq st (substr s_temp si o_slen))))
  93.                  (if (= st o_str)
  94.                    (progn
  95.                      (setq s_temp (strcat
  96.                                     (if (> si 1)
  97.                                       (substr s_temp 1 (1- si))
  98.                                       ""
  99.                                     )
  100.                                     n_str
  101.                                     (substr s_temp (+ si o_slen))
  102.                                   )
  103.                      )
  104.                      (setq chf t)    ; Found old string
  105.                      (setq si (+ si n_slen))
  106.                    )
  107.                    (setq si (1+ si))
  108.                  )
  109.                )
  110.                (if chf
  111.                  (progn              ; Substitute new string for old
  112.                    ; Modify the TEXT entity
  113.                    (entmod (subst (cons 1 s_temp) (assoc 1 ent) ent))
  114.                    (setq chm (1+ chm))
  115.                  )
  116.                )
  117.              )
  118.            )
  119.            (setq last_o (1+ last_o))
  120.          )
  121.        )
  122.        ;; else go on to the next line...
  123.      )
  124.    )
  125. )
  126. (if (/= (type objs) 'ENAME)
  127.    (if (/= (sslength objs) 1)        ; Print total lines changed
  128.      (princ (strcat "Changed "
  129.                     (rtos chm 2 0)
  130.                     " text lines."
  131.             )
  132.      )
  133.    )
  134. )
  135. (terpri)
  136. )
  137. ;;;
  138. ;;; Main procedure for manipulating text entities
  139. ;;; ARGUMENTS:
  140. ;;;   typ   -- Type of operation to perform
  141. ;;;   prmpt -- Partial prompt string to insert in standard prompt line
  142. ;;;   fld   -- Assoc field to be changed
  143. ;;; GLOBALS:
  144. ;;;   sset  -- The selection set of text entities
  145. ;;;
  146. (defun cht_pe (typ prmpt fld / temp ow nw ent tw sty w hw lw
  147.                              sslen n sn ssl)
  148. (if (= (sslength sset) 1)           ; Special case if there is only
  149.                                      ; one entity selected
  150.    ;; Process one entity.
  151.    (cht_p1)
  152.    ;; Else
  153.    (progn
  154.      ;; Set prompt string.
  155.      (cht_sp)
  156.      (if (= nw "List")
  157.        ;; Process List request.
  158.        (cht_pl)
  159.        (if (= nw "Individual")
  160.          ;; Process Individual request.
  161.          (cht_pi)
  162.          (if (= nw "Select")
  163.            ;; Process Select request.
  164.            (cht_ps)
  165.            ;; Else
  166.            (progn
  167.              (if (= typ "Rotation")
  168.                (setq nw (* (/ nw 180.0) pi))
  169.              )
  170.              (if (= (type nw) 'STR)
  171.                (if (not (tblsearch "style" nw))
  172.                  (progn
  173.                    (princ (strcat "\nStyle " nw " not found. "))
  174.                  )
  175.                  (cht_pa)
  176.                )
  177.                (cht_pa)
  178.              )
  179.            )
  180.          )
  181.        )
  182.      )
  183.    )
  184. )
  185. )
  186. ;;;
  187. ;;; Change all of the entities in the selection set.
  188. ;;;
  189. (defun cht_pa (/ cht_oh temp)
  190. (setq sslen (sslength sset))
  191. (setq cht_oh (getvar "highlight"))
  192. (setvar "highlight" 0)
  193. (while (> sslen 0)
  194.    (setq temp (ssname sset (setq sslen (1- sslen))))
  195.    (entmod (subst (cons fld nw)
  196.                   (assoc fld (setq ent (entget temp)))
  197.                   ent
  198.            )
  199.    )
  200.    
  201. )
  202. (setvar "highlight" cht_oh)
  203. )
  204. ;;;
  205. ;;; Change one text entity.
  206. ;;;
  207. (defun cht_p1 ()
  208. (setq temp (ssname sset 0))
  209. (setq ow (cdr(assoc fld (entget temp))))
  210. (if (= opt "Rotation")
  211.    (setq ow (/ (* ow 180.0) pi))
  212. )
  213. (redraw (cdr(assoc -1 (entget temp))) 3)
  214. (initget 0)
  215. (if (= opt "Style")
  216.    (setq nw (getstring (strcat "\nNew " prmpt ". <"
  217.                              ow ">: ")))
  218.    (setq nw (getreal (strcat "\nNew " prmpt ". <"
  219.                              (rtos ow 2) ">: ")))
  220. )
  221. (if (or (= nw "") (= nw nil))
  222.    (setq nw ow)
  223. )
  224. (redraw (cdr(assoc -1 (entget temp))) 1)
  225. (if (= opt "Rotation")
  226.    (setq nw (* (/ nw 180.0) pi))
  227. )
  228. (if (= opt "Style")
  229.    (if (null (tblsearch "style" nw))
  230.      (princ (strcat "\nStyle " nw " not found. "))
  231.      
  232.      (entmod (subst (cons fld nw)
  233.                     (assoc fld (setq ent (entget temp)))
  234.                     ent
  235.              )
  236.      )
  237.    )
  238.    (entmod (subst (cons fld nw)
  239.                   (assoc fld (setq ent (entget temp)))
  240.                   ent
  241.            )
  242.    )
  243. )
  244. )
  245. ;;;
  246. ;;; Set the prompt string.
  247. ;;;
  248. (defun cht_sp ()
  249. (if (= typ "Style")
  250.    (progn
  251.      (initget "Individual List New Select ")
  252.      (setq nw (getkword (strcat "\nIndividual/List/Select style/<New "
  253.                                 prmpt
  254.                                 " for all text entities>: ")))
  255.      (if (or (= nw "") (= nw nil) (= nw "Enter"))
  256.        (setq nw (getstring (strcat "\nNew "
  257.                                    prmpt
  258.                                    " for all text entities: ")))
  259.      )
  260.    )
  261.    (progn
  262.      (initget "List Individual" 1)
  263.      (setq nw (getreal (strcat "\nIndividual/List/<New "
  264.                                 prmpt
  265.                                 " for all text entities>: ")))
  266.    )
  267. )
  268. )
  269. ;;;
  270. ;;; Process List request.
  271. ;;;
  272. (defun cht_pl ()
  273. (setq unctr (1- unctr))
  274. (setq sslen (sslength sset))
  275. (setq tw 0)
  276. (while (> sslen 0)
  277.    (setq temp (ssname sset (setq sslen (1- sslen))))
  278.    (if (= typ "Style")
  279.      (progn
  280.        (if (= tw 0)
  281.          (setq tw (list (cdr(assoc fld (entget temp)))))
  282.          (progn
  283.            (setq sty (cdr(assoc fld (entget temp))))
  284.            (if (not (member sty tw))
  285.              (setq tw (append tw (list sty)))
  286.            )
  287.          )
  288.        )
  289.      )
  290.      (progn
  291.        (setq tw (+ tw (setq w (cdr(assoc fld (entget temp))))))
  292.        (if (= (sslength sset) (1+ sslen)) (setq lw w hw w))
  293.        (if (< hw w) (setq hw w))
  294.        (if (> lw w) (setq lw w))
  295.      )
  296.    )
  297. )
  298. (if (= typ "Rotation")
  299.    (setq tw (* (/ tw pi) 180.0)
  300.          lw (* (/ lw pi) 180.0)
  301.          hw (* (/ hw pi) 180.0))
  302. )
  303. (if (= typ "Style")
  304.    (progn
  305.      (princ (strcat "\n"
  306.                     typ
  307.                     "(s) -- "))
  308.      (princ tw)
  309.    )
  310.    (princ (strcat "\n"
  311.                     typ
  312.                     " -- Min: "
  313.                     (rtos lw 2)
  314.                     "\t Max: "
  315.                     (rtos hw 2)
  316.                     "\t Avg: "
  317.                     (rtos (/ tw (sslength sset)) 2) ))
  318. )
  319. )
  320. ;;;
  321. ;;; Process Individual request.
  322. ;;;
  323. (defun cht_pi ()
  324. (setq sslen (sslength sset))
  325. (while (> sslen 0)
  326.    (setq temp (ssname sset (setq sslen (1- sslen))))
  327.    (setq ow (cdr(assoc fld (entget temp))))
  328.    (if (= typ "Rotation")
  329.      (setq ow (/ (* ow 180.0) pi))
  330.    )
  331.    (initget 0)
  332.    (redraw (cdr(assoc -1 (entget temp))) 3)
  333.    (if (= typ "Style")
  334.      (progn
  335.        (setq nw (getstring (strcat "\nNew "
  336.                                   prmpt
  337.                                   ". <"
  338.                                   ow ">: ")))
  339.      )
  340.      (progn
  341.        (setq nw (getreal (strcat "\nNew "
  342.                                   prmpt
  343.                                   ". <"
  344.                                (rtos ow 2) ">: ")))
  345.      )
  346.    )
  347.    (if (or (= nw "") (= nw nil))
  348.      (setq nw ow)
  349.    )
  350.    (if (= typ "Rotation")
  351.      (setq nw (* (/ nw 180.0) pi))
  352.    )
  353.    (entmod (subst (cons fld nw)
  354.                   (assoc fld (setq ent (entget temp)))
  355.                   ent
  356.            )
  357.    )
  358.    (redraw (cdr(assoc -1 (entget temp))) 1)
  359. )
  360. )
  361. ;;;
  362. ;;; Process the Select option.
  363. ;;;
  364. (defun cht_ps ()
  365. (princ "\nSearch for which Style name?  <*>: ")
  366. (setq sn  (strcase (getstring))
  367.        n   -1
  368.        nsset (ssadd)
  369.        ssl (1- (sslength sset))
  370.        )
  371. (if (or (= sn "*") (null sn) (= sn ""))
  372.    (setq nsset sset sn "*")
  373.    (while (and sn (< n ssl))
  374.      (setq temp (ssname sset (setq n (1+ n))))
  375.      (if (= (cdr(assoc 7 (entget temp))) sn)
  376.        (ssadd temp nsset)
  377.      )
  378.    )
  379. )
  380. (setq ssl (sslength nsset))  
  381. (princ "\nFound ")
  382. (princ ssl)
  383. (princ " text entities with STYLE of ")
  384. (princ sn)
  385. (princ ". ")
  386. )
  387. ;;;
  388. ;;; The C: function definition.
  389. ;;;
  390. (defun c:cht    () (chtxt))
  391. (princ "\n\tc:CHText loaded.  Start command with CHT.")
  392. (princ)

 
谢谢大家
回复

使用道具 举报

29

主题

196

帖子

168

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
145
发表于 2022-7-6 13:50:05 | 显示全部楼层
 
我已经贴了好几次了。。。。。此例程允许您更改选定文本、多行文字和属性中的所有内容。。。
 
它通过对话框工作。
133045gl5ce0cbnu6tnzum.jpg
133048zpmmplqf6imfyzvz.jpg
dt。拉链
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 06:06 , Processed in 0.354407 second(s), 58 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表