小灰345 发表于 2014-2-9 10:13:19

多行文字转单行文字

请问多行文字如何转为单行文字
是否有插件可以使用?谢谢大家了

greg.battin 发表于 2018-2-14 03:31:59

Here is an old LISP routine from 1998 that can be used for learning
I hope it helps
~Greg

Tip1455.LSP: MMTEXT.LSP Mtext to Text (c) 1998, Jim Houser
(defun C: MTT (/        en ent nent lyr        ipt tsz        txt sty        elv spc        ts pt pty npty
              ptx ptz npt)
(setq         en (car (entsel "\ nSelect MTEXT to change to regular text"))
        ent (entget en)
        nent (car ent)
)
(setq         lyr (assoc 8 ent)
        ipt (assoc 10 ent)
        tsz (assoc 40 ent)
        txt (assoc 1 ent)
        sty (assoc 7 ent)
        elv (assoc 210 ent)
        spc (assoc 67 ent)
)
(setq         ts (cdr tsz)
        pt (cdr ipt)
        pty (cadr pt)
        npty (- pty ts)
        ptx (car pt)
        ptz (caddr pt)
        npt (list ptx npty ptz)
        ipt (cons 10 npt)
)
(setq         nent
       (list nent
             (cons 0 "TEXT")
             (cons 100 "AcDbEntity")
             spc
             lyr
             (cons 100 "AcDbText")
             ipt
             tsz
             txt
             (cons 50 0.0)
             (cons 41 1.0)
             (cons 51 0.0)
             sty
             (cons 71 0)
             (cons 72 0)
             (cons 11 (list 0.0 0.0 0.0))
             elv
             (cons 73 0)
       )
)
(entdel en)
(entmake nent)
(princ)
)[/ code]

wmz 发表于 2020-10-11 18:25:48

;;;;;;取多行文字函数(e---多行文字图元对象名称,调用:(MtoT e))
(defun MtoT(e / ee str n n1 nn str0 str1 stra)
    (vl-load-com)
    (setq    n nil nn 0 str0 "" str1 "" stra "")
    (setq   ee (entget e))
    (setqstr (cdr(assoc 1 ee)))
    (while
         (setq   n (vl-string-search ";" str))
         (setq str (substr str (+ n 2))) ;;;;;;取格式符以后的字符串,无格式符则忽略
    )
    (setqstr (vl-string-subst "" "}" str)) ;;;;;去掉尾符号,无格式符则忽略
    (setq   nn (strlen str) n1 1 stra "")
   ;;;;;以下循环去除换行符"\P"但保留不属于换行的大写字符P——高手们可将下面的代码简化或优化
    (repeat nn
         (setq str1 "" str0 "")
         (setq str0 (substr str n1 1) n1 (1+ n1))
         (if (and(> n1 2)(<= n1 nn))(setq str1 (substr str (- n1 2) 1)))
      (cond ((and(= str0 "P")(/= str1 "\\"))(setq stra (strcat stra str0)))
          ((and(/= str0 "\\")(/= str0 "P"))(setq stra (strcat stra str0)))
      )
    )
       stra ;;;;;单行文字全字符串
)

wmz 发表于 2020-10-3 15:21:19

;;;;;;;分解法取多行文字
(defun c:text()
    (setq f (open "C:/aaa.txt" "w"))
    (setq e (ssget "X" '((0 . "MTEXT"))))
    (setq n (sslength e) m 0 strb '())
(repeat n
    (setq e1 (ssname e m) m (1+ m) d1 nil d2 nil)
    (setq e2 (entget e1))
    (setqp (cdr(assoc 10 e2)));;;左上角坐标
    (setq d1 (cdr(assoc 42 e2)));;;宽度
    (setq d2 (cdr(assoc 43 e2)));;;高度
    (setq p1 (polar p 4.71238898 d2))
    (setq p2 (polar p 0.0 d1))
    (command"_.explode" e1)
    (setqs (ssget "c" p1 p2 '((0 . "TEXT"))))
    (setq nn (sslength s) mm 0 hh '())
    (repeat nn
      (setq s1 (entget(ssname s mm)) mm (1+ mm))
      (setq h1 (cdr(assoc 1 s1)))
      (setq hh (cons (list h1) hh))
    )
       (setq str "")
   (foreach z hh
       (setq str (strcat str (car z)))
   )
       (setq strb (cons (list str) strb))
       (command "_.undo" 1)
);;;;;;end n
   (foreach z strb
      (setq pp (car z))
      (write-line pp f)
   )
   (close f)
)

自贡黄明儒 发表于 2014-2-9 10:24:04

本帖最后由 自贡黄明儒 于 2014-2-9 10:26 编辑

爆破就可以了,(command "_.explode"

小灰345 发表于 2014-2-9 10:30:10

自贡黄明儒 发表于 2014-2-9 10:24 static/image/common/back.gif
爆破就可以了,(command "_.explode"

谢谢了

lxdz443 发表于 2014-2-10 07:46:55

;----------------------------------
;----------------------------------
;       多行文字转单行文字
;----------------------------------
;----------------------------------
(defun c:xx( / myosmode cmdmode sset ssl nsset temp ssl1 total txt_h txt_p txt_s txt_en txt_tx txt_tx1 txt_tx2 txt_tx3 txt1_l txt1_s txt1_c i_1)
(if *error* quit)
(setq cmdmode (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq myosmode (getvar "osmode"))
(setvar "osmode" 0)
(prompt "\n选择需要求和的数据: ")
(setq sset (ssget))
(if (null sset)
(princ "\n错误: 没有选择对象!\n")
;过滤出选中的“text”实体,并报告有多少“text”实体被选中。
(progn
(setq ssl (sslength sset))
(setq nsset (ssadd))
(while (> ssl 0)
(setq temp (ssname sset (setq ssl(1- ssl))))
(if (= (cdr (assoc 0 (entget temp))) "MTEXT")
(ssadd temp nsset)
)
)
(setq ssl (sslength nsset))
(princ "共选择了 ")
(princ ssl)
(princ " 个多行文字.")
;选出所有可转化为数的“TEXT”,并求和。
(setq ssl1 ssl)
(if (= (CDR (ASSOC '3 (TBLSEARCH "STYLE" "多转单"))) nil)
    (command "style" "多转单" "宋体" "" "" "" "" ""))
(while (> ssl 0)
(setq temp (ssname nsset (setq ssl (1- ssl))))
(setq txt_h (cdr (assoc 40 (entget temp))))
(setq txt_p (cdr (assoc 10 (entget temp))))
(setq txt_s (cdr (assoc 71 (entget temp))))
(setq txt_en (/ (* (cdr (assoc 50 (entget temp))) 180) Pi))
(setq txt_tx (cdr (assoc 1 (entget temp))))
(setq txt1_s 1)
(setq txt1_l (strlen txt_tx))
(setq i_1 txt1_l)
(setq txt_tx1 0)
(setq txt_tx2 0)
(setq txt_tx3 0)
(while (> i_1 0)
;如果文字有多行,则不转换
   (if (= (substr txt_tx i_1 1) "P")
       (if (> i_1 1)
         (if (= (substr txt_tx (- i_1 1) 1) "\\")
               (setq txt1_s 0))))

;找到“{”符号位置
   (if (= (substr txt_tx i_1 1) "{")
       (if (> i_1 1)
         (if (/= (substr txt_tx (- i_1 1) 1) "\\")
               (setq txt_tx1 i_1)
               (setq txt1_s 0))
         (setq txt_tx1 i_1)))

;找到“}”符号位置
   (if (= (substr txt_tx i_1 1) "}")
       (if (> i_1 1)
         (if (/= (substr txt_tx (- i_1 1) 1) "\\")
               (setq txt_tx3 i_1)
               (setq txt1_s 0))
         (setq txt_tx3 i_1)))

   (setq i_1 (1- i_1))
)

;找到“{”“}”符号中间的“;”位置
(if (and (> txt_tx1 0) (> txt_tx3 txt_tx1))
   (progn
       (setq i_1 txt_tx3)
       (while (> i_1 txt_tx1)
         (if (= (substr txt_tx i_1 1) ";")
               (setq txt_tx2 i_1))
         (setq i_1 (1- i_1)))
))


(if (= txt1_s 1)
(progn

;形如“{*****}”
(if (and (= txt_tx1 1) (= txt_tx3 txt1_l))
    (setq txt_tx (substr txt_tx (+ txt_tx2 1) (- txt_tx3 txt_tx2 1))))

;形如“{*****}***”
(if (and (= txt_tx1 1) (< txt_tx3 txt1_l))
    (setq txt_tx (strcat (substr txt_tx (+ txt_tx2 1) (- txt_tx3 txt_tx2 1)) (substr txt_tx (+ txt_tx3 1) (- txt1_l txt_tx3)) )))

;形如“***{*****}”
(if (and (> txt_tx1 1) (= txt_tx3 txt1_l))
    (setq txt_tx (strcat (substr txt_tx 1 (- txt_tx1 1)) (substr txt_tx (+ txt_tx2 1) (- txt_tx3 txt_tx2 1)) )))

;形如“***{*****}***”
(if (and (> txt_tx1 1) (< txt_tx3 txt1_l))
    (setq txt_tx (strcat (substr txt_tx 1 (- txt_tx1 1)) (substr txt_tx (+ txt_tx2 1) (- txt_tx3 txt_tx2 1)) (substr txt_tx (+ txt_tx3 1) (- txt1_l txt_tx3)) )))

(entdel temp)
(cond ((= txt_s 1) (command "text" "s" "多转单" "j" "tl" txt_p txt_h txt_en txt_tx))
      ((= txt_s 2) (command "text" "s" "多转单" "j" "tc" txt_p txt_h txt_en txt_tx))
      ((= txt_s 3) (command "text" "s" "多转单" "j" "tr" txt_p txt_h txt_en txt_tx))
      ((= txt_s 4) (command "text" "s" "多转单" "j" "ml" txt_p txt_h txt_en txt_tx))
      ((= txt_s 5) (command "text" "s" "多转单" "j" "mc" txt_p txt_h txt_en txt_tx))
      ((= txt_s 6) (command "text" "s" "多转单" "j" "mr" txt_p txt_h txt_en txt_tx))
      ((= txt_s 7) (command "text" "s" "多转单" "j" "bl" txt_p txt_h txt_en txt_tx))
      ((= txt_s 8) (command "text" "s" "多转单" "j" "bc" txt_p txt_h txt_en txt_tx))
      ((= txt_s 9) (command "text" "s" "多转单" "j" "br" txt_p txt_h txt_en txt_tx)))
))
(setq ssl1 (1- ssl1))
) ) )

(setvar "OSMODE" myosmode)
(setvar "CMDECHO" cmdmode)
(prin1)
)

flyfox1047 发表于 2014-2-10 08:26:01

lxdz443 发表于 2014-2-10 07:46 static/image/common/back.gif
;----------------------------------
;----------------------------------
;       多行文字转单行文字 ...

explode不方便?干嘛还整个代码?你确定这样能行?

lxdz443 发表于 2014-2-10 09:11:40

很久以前在网上找的画通信杆路里面自带的,就收藏到硬盘里面了,一直没有使用过。

香田里浪人 发表于 2014-2-11 10:58:33

编程精神可嘉,可是,适用意义并不大。

伪书虫86 发表于 2014-9-4 10:14:58

自贡黄明儒 发表于 2014-2-9 10:24 static/image/common/back.gif
爆破就可以了,(command "_.explode"

爆破会有个问题,爆破后的单行文字,中文英文啥的都各自变成一个个单体了

llsheng_73 发表于 2014-9-7 10:37:53

lxdz443 发表于 2014-2-10 07:46 static/image/common/back.gif
;----------------------------------
;----------------------------------
;       多行文字转单行文字 ...

谢谢分享,有空测试后收藏

zlzxtfl 发表于 2016-5-27 09:00:17

怎样,我使用没有反应的
页: [1] 2 3
查看完整版本: 多行文字转单行文字