明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4436|回复: 18

[求助]各位大侠,怎样将CAD中明细表的内容导出倒文本文件那??

  [复制链接]
发表于 2003-4-1 19:47 | 显示全部楼层 |阅读模式
我的CAD中的明细表 每一列高度都是相等的,而且 它的列数是不确定的,
  有没有好的办法判断  让程序自己导出文字 直到明细表没有为止,
  并且导出后的 文字是有顺序的, 谢谢了!!
发表于 2003-4-2 08:55 | 显示全部楼层

要自己编程,好象有专门的软件,到网上找找。我自己试过,但必须每列都有内容。

 楼主| 发表于 2003-4-3 09:39 | 显示全部楼层

大侠!!需要你的帮助!

我从CAD中导出到文本文件中 的文字形式 是{\f宋体|b0|i0|c134|p54;活动底板}  {\f宋体|b0|i0|c134|p2;48652-1-1}  怎样才能去掉{\f宋体|b0|i0|c134|p54;} 只要 “活动底板”字样那??
谢谢了!!!
发表于 2003-4-3 09:45 | 显示全部楼层

给你个函数吧

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;功能:获取文字对象中的文字字符串;;;
;sname--文字对象名;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun Getext(sname / sinf str str2)
  (setq sinf (entget sname))
  (setq str (cdr (assoc 1 sinf)))
  (setq str (strcase str 0))
  (setq str (vl-string-trim "{}" str))
  (if (= (type (read str)) 'SYM)
    (progn
      (setq str2 (vl-symbol-name (read str)))
      (if (/= (strlen str) (strlen str2))
        (progn
          (setq str2 (strcase str2 0))
          (setq str (vl-string-left-trim str2 str))
          (setq str (vl-string-left-trim ";" str))
        )
      )       
    )
  )
  str
)
发表于 2003-4-3 10:56 | 显示全部楼层

Hopefully this will help you...

;Usage: Outext
;Select texts or mtext in the drawings
;These texts or mtext will be sent to D:outext.txt
;(overide if the file exists) in an order of
;their Y value of their insert point in the drawing.
;Format of mtext hopefully will be removed.
;
(defun C:Outext(/ ss idx txtlst cnt f)
  (setq ss (ssget)
        idx 0
        txtlst '())
  (while (<= idx (1- (sslength ss)))
    (if (member (cdr (assoc 0 (setq ed (entget
           (ssname ss idx))))) '("MTEXT" "TEXT"))
        (setq txtlst (append txtlst
           (list (list (cdr (assoc 1 ed)) (caddr (assoc 10 ed))))))
    );endif
    (setq idx (1+ idx))
  )
  (setq txtlst (vl-sort txtlst
                         (function (lambda (e1 e2)
                               (> (cadr e1) (cadr e2))))))
  (setq txtlst (mapcar 'car txtlst))
  (setq f (open "d:outext.txt" "w") cnt 0)
  (while (<= cnt (1- (length txtlst)))
    (write-line (remove-style (nth cnt txtlst)) f)
    (setq cnt (1+ cnt))
  )
  (close f)
  (princ)
)
;------------------------------------------------
(defun remove-style(text0 / pos)
(if (getstyle text0)
  (progn
    (setq pos (strlen (getstyle text0)))
    (vl-string-right-trim "}" (substr text0 (1+ pos)))
  )
  text0
)
)  
;----------------------------------------------
(defun getstyle(text0 / text pos0 pos1 LOOP symb)
  (if (vl-string-search "\\\\" text0)
      (setq text (vl-string-subst "||||" "\\\\" text0))
      (setq text text0)
  )
  (setq pos1 (vl-string-search "{" text))
  (if (= pos1 0)
        (progn
          (setq LOOP T)
          (while LOOP
            (setq pos1 (vl-string-search "\\" text (setq pos (1+ pos1))))
            (if (/= pos1 pos)
                (progn
                   (setq LOOP nil)
                   (setq pos0 pos)
                 );progn
                (progn
                  (setq symb (substr text (setq pos1 (+ 2 pos1)) 1))
                  (cond ((or (= symb "L")(= symb "O"))
                         (setq pos1 (1- pos1))
                        )
                        ((or (= symb "F")(= symb "f")(= symb "C")(= symb "H")
                             (= symb "T")(= symb "Q")(= symb "W"))
                         (setq pos1 (vl-string-search ";" text pos1))
                        )
                  );cond
                );progn
            );endif
           );while
          (substr text 1 pos0)
        );progn
    nil
  );endif
)
;;;
发表于 2003-4-3 12:33 | 显示全部楼层

Removes MTEXT formatting (供參考)

Having a reason to compare the value of groups of Mtext/Text in an Xref to
groups of Mtext/Text in the host drawing, I decided to attack the Mtext
formatting, in hopes of reducing it to a simple string equivalent.  Tony said it
was difficult with AutoLisp, but I hope he was referring only to find *and*
replace algorithms.  While risking public ridicule, I'd appreciate it if you
sages would test and comment  (easy now, Tony).

;;===========================================================
;; UNFORMAT.LSP (c)2003, John F. Uhden, Cadlantic/CADvantage
;; v1.0 (04-01-03)
;; Removes MTEXT formatting with option to retain the "\\P" LineFeeds
;;
;; Arguments:
;;   Mtext  - either an Ename or VLA-Object
;;   KeepLF - nil (discard LineFeeds) non-nil (retain LineFeeds)
;;
;; NOTES:
;;   Only R15 or higher.
;;   v1.0 is only the first attempt.
;;   We can always embellish the code with additional options.
;;   Yes, it can probably be sped up using integers, but this is legible.
;;
(defun UnFormat (Mtext KeepLF / Text Str)
  (vl-load-com)
  (cond
    ((= (type Mtext) 'VLA-Object))
    ((= (type Mtext) 'ENAME)
      (setq Mtext (vlax-ename->vla-object Mtext))
    )
    (1 (setq Mtext nil))
  )
  (and
    Mtext
    (= (vlax-get Mtext 'ObjectName) "AcDbMText")
    (setq Mtext (vlax-get Mtext 'TextString))
    (setq Text "")
    (while (/= Mtext "")
      (cond
        ((wcmatch (strcase (setq Str (substr Mtext 1 2))) "\\[\\{}`~]")
          (setq Mtext (substr Mtext 3)
                Text   (strcat Text Str)
          )
        )
        ((wcmatch (substr Mtext 1 1) "[{}]")
          (setq Mtext (substr Mtext 2))
        )
        ((and KeepLF (wcmatch (strcase (substr Mtext 1 2)) "\\P"))
          (setq Mtext (substr Mtext 3)
                Text  (strcat Text "\\P")
          )
        )
        ((wcmatch (strcase (substr Mtext 1 2)) "\\[LOP]")
          (setq Mtext (substr Mtext 3))
        )
        ((wcmatch (strcase (substr Mtext 1 2)) "\\[ACFHQTW]")
          (setq Mtext (substr Mtext (+ 2 (vl-string-search ";" Mtext))))
        )
        ((wcmatch (strcase (substr Mtext 1 2)) "\\S")
          (setq Str   (substr Mtext 3 (- (vl-string-search ";" Mtext) 2))
                Text  (strcat Text (vl-string-translate "#^\\" "   " Str))
                Mtext (substr Mtext (+ 4 (strlen Str)))
          )
          (print Str)
        )
        (1
          (setq Text (strcat Text (substr Mtext 1 1))
                Mtext (substr Mtext 2)
          )
        )
      )
    )
  )
  Text
)

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ
 楼主| 发表于 2003-4-3 23:53 | 显示全部楼层

求助 大侠 怎样判断 所选范围为空那?

1        中国        香港        澳门
2        日本        nil        东京
3        美国        纽约        nil
  这是明细表中的内容 怎样判断 当所选范围为 空时导出到
   文本文件中的内容为 nil 呀
  还有就是 我想导出的形式是  1  中国  香港  澳门
                             2  日本  nil   东京
怎么样才能实现呀?
谢谢了
发表于 2003-4-4 08:47 | 显示全部楼层

这比较困难

如果是一次性选择,你除非知道什么位置是空的,输出时,在其位置上写上空,否则,你选择的就是那些非空的对象,空的将不可能被选择。
不过你可以按位置一个一个选择,也就是你能确定每个文字对象的位置及其大小,按其位置一个一个地框选,如果选择集长度为0,则为空。
 楼主| 发表于 2003-4-4 13:56 | 显示全部楼层

求助    谢谢 meflying 兄   但是我的明细表 的大小

本帖最后由 作者 于 2003-4-4 13:56:12 编辑

求助    谢谢 meflying 兄   但是我的明细表 的大小是不确定,有没有好的办法呀????[br]meflying兄 你说的那种情况我已经解决的  ,就是我说的那种情况有没有好的 办法解决呀,就是因为我得 明细表的大小不确定 (总高度不确定)。但是 每一 列 之间的距离是固定的(80)
   所以 范围我确定不来,束手无策。
   在这里希望得到 给位大侠的帮助!!!!
发表于 2003-4-4 11:58 | 显示全部楼层

我正在做,好多烦事,可能下星期吧

其实如果你的宽度确定的话,你可以根据第一列(序号)来确定高度。一般序号这列不可能为空的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-4 21:22 , Processed in 0.363726 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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