明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1827|回复: 17

[源码] 多行文字炸开法速度很慢,不知这个咋样

[复制链接]
发表于 2020-10-11 15:08 | 显示全部楼层 |阅读模式
本帖最后由 wmz 于 2020-10-11 15:09 编辑
  1. ;;;;;;;将多行文字转换为单行文字
  2. (defun c:MtoTa(/ f e e0 ee m str p0 pp h H0 KD n n1 nn str0 str1 stra)
  3.     (vl-load-com)
  4.    ; (setq    f (open "C:/10.txt" "w"))
  5.     (setq    e (ssget "X" '((0 . "MTEXT"))))
  6.   (if e (progn
  7.     (setq    m 0 n nil nn 0 str0 "" str1 "" stra "")
  8.   (repeat (sslength e)
  9.     (setq   e0 (ssname e m) m (1+ m))
  10.     (setq   ee (entget e0))
  11.     (setq  str (cdr(assoc 1 ee)))
  12.     (setq   p0 (cdr(assoc 10 ee)))
  13.     (setq    H (cdr(assoc 40 ee)))
  14.     (setq   H0 (cdr(assoc 43 ee)))
  15.     (setq   KD (cdr(assoc 42 ee)))
  16.     (setq   pp (list (+(car p0)(/ KD 2.0))(-(cadr p0)(/ H0 2.0))))
  17.     (while
  18.          (setq   n (vl-string-search ";" str))
  19.          (setq str (substr str (+ n 2)))
  20.     )
  21.     (setq  str (vl-string-subst "" "}" str))
  22.     (setq   nn (strlen str) n1 1 stra "")
  23.     (repeat nn
  24.          (setq str1 "" str0 "")
  25.          (setq str0 (substr str n1 1) n1 (1+ n1))
  26.          (if (and(> n1 2)(<= n1 nn))(setq str1 (substr str (- n1 2) 1)))
  27.       (cond ((and(= str0 "P")(/= str1 "\"))(setq stra (strcat stra str0)))
  28.                ((and(/= str0 "\")(/= str0 "P"))(setq stra (strcat stra str0)))
  29.       )        
  30.     );;;;;;end nn
  31.       (command "erase" e0 "")
  32.       (command "TEXT" "M" pp h "360" stra)
  33.       ;(write-line stra f)
  34.       (print "stra=")(princ stra)(princ)
  35.   )
  36.   ));;;;;end (if e  
  37.       ;(close f)
  38. )


"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2020-10-24 13:58 | 显示全部楼层
;;;;;;;将多行文字转换为单行文字
(defun c:MtoTa(/ f e e0 ee m str p0 pt h H0 KD n n1 nn str0 str1 stra)
    (vl-load-com)
    (setq    e (ssget "X" '((0 . "MTEXT"))))
  (if e (progn
    (setq    m 0 n nil nn 0 str0 "" str1 "" stra "")
  (repeat (sslength e)
    (setq   e0 (ssname e m) m (1+ m))
    (setq   ee (entget e0))
    (setq  str (cdr(assoc 1 ee)))
    (setq  sty (cdr(assoc 7 ee)))
    (setq  ply (cdr(assoc 8 ee)))
    (setq   p0 (cdr(assoc 10 ee)))
    (setq    H (cdr(assoc 40 ee)))
    (setq   H0 (cdr(assoc 43 ee)))
    (setq   KD (cdr(assoc 42 ee)))
    (setq   pt (list (+(car p0)(/ KD 2.0))(-(cadr p0)(/ H0 2.0)) 0.0))
    (while
         (setq   n (vl-string-search ";" str))
         (setq str (substr str (+ n 2)))
    )
    (setq  str (vl-string-subst "" "}" str))
    (setq   nn (strlen str) n1 1 stra "")
    (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 ((= str0 "\\")(setq stra (strcat stra "")))
;            ((and(= str0 "P")(= str1 "\\"))(setq stra (strcat stra "")))
      (cond ((and(= str0 "P")(/= str1 "\\"))(setq stra (strcat stra str0)))
            ((and(/= str0 "\\")(/= str0 "P"))(setq stra (strcat stra str0)))
      )             
    );;;;;;end nn
      (command "erase" e0 "")
    ;  (command "layer" "s" ply "")
    ;  (command "TEXT" "M" pt "3.0" "360" stra)
   (entmake (list
           '(0 . "TEXT")
           (cons 1 stra)
           (cons 7 sty)
           (cons 8 ply)
           (cons 10 pt)
           (cons 11 pt)
           (cons 40 h)
           (cons 41 0.9)
           (cons 50 0.0)
           '(72 . 4)
           '(73 . 0)
          )
    )
  )
  ));;;;;end (if e  
)
用这个看看
发表于 2022-5-29 14:38 | 显示全部楼层
wmz 发表于 2020-10-24 13:58
;;;;;;;将多行文字转换为单行文字
(defun c:MtoTa(/ f e e0 ee m str p0 pt h H0 KD n n1 nn str0 str1 st ...

好用,(setq    e (ssget "X" '((0 . "MTEXT"))))改为(setq    e (ssget '((0 . "MTEXT"))))
即可由自动选择图形中所有的多行文字 改为 手动选择要转换的多行文字
发表于 2020-10-15 17:40 | 显示全部楼层
wmz 发表于 2020-10-15 12:44
我是须要你上传DWG图幅,便于我调试程序。不是上传PNG图像文件。再说这个文件我也打不开(不知什么原因) ...

图上传了,跟图没关系吧,主要是程序不能启动

本帖子中包含更多资源

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

x
发表于 2020-10-12 09:07 | 显示全部楼层
顶一下,,谢谢楼主的分享
发表于 2020-10-12 14:09 | 显示全部楼层
顶一下,,谢谢楼主的分享
发表于 2020-10-13 17:15 | 显示全部楼层
(setq   n (vl-string-search ";" str))这句好像有问题
发表于 2020-10-13 18:00 | 显示全部楼层
; 错误: 参数类型错误: numberp: nil
 楼主| 发表于 2020-10-14 13:56 | 显示全部楼层
本帖最后由 wmz 于 2020-10-14 13:58 编辑
广易精通 发表于 2020-10-13 18:00
; 错误: 参数类型错误: numberp: nil

请发一幅遇到问题的图,我测试一下!谢谢!(acad2012版本以下,我没有装更高版本的CAD)
发表于 2020-10-15 11:19 | 显示全部楼层
2010CAD加载也是这个错误提示,感觉还是程序有问题
发表于 2020-10-15 11:26 | 显示全部楼层
wmz 发表于 2020-10-14 13:56
请发一幅遇到问题的图,我测试一下!谢谢!(acad2012版本以下,我没有装更高版本的CAD)

图片已上传

本帖子中包含更多资源

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

x
 楼主| 发表于 2020-10-15 12:44 | 显示全部楼层

我是须要你上传DWG图幅,便于我调试程序。不是上传PNG图像文件。再说这个文件我也打不开(不知什么原因),麻烦你了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-25 07:24 , Processed in 0.209340 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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