明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1433|回复: 3

各位大哥帮忙看一下程序。

[复制链接]
发表于 2005-1-27 18:11:00 | 显示全部楼层 |阅读模式
在各位大哥的指点下我完成了第一个程序,现在程序是能运行了,但是需要大家帮忙瘦身一下。软件的功能是对从VISIO导过来的CAD文件进行处理,部分字进行分层,部分线该为指定宽度的多义线。 (defun c:test (/ ss )
(setvar "cmdecho" 0)
(command "undo" "be") ;
(command ".LAYER" "S" "ANT" "") ;选择ANT层为当前层。
(command "fillmode" "1") (setq ss (ssget "X" '((0 . "MTEXT") (8 . "ANT"))));选择ANT层的多行字体
(setq i 0)
(while (< i (sslength ss))
(command "explode" (ssname ss i)) ;炸开
(setq i (1+ i))
) (setq lay1 "0" lay2 "编号" lay3 "DIVIDER" lay4 "COUPLER")
(command "_.layer" "m" lay2 "m" lay3 "m" lay4 "") ;建层(主要是我不知道如何对错误的判断,如:没有DIVIDER的层,所以建了一层)
(setq layern "DIVIDER") (command "_LAYER" "S" layern "")
(command "_mtext" "5,5" "h" "0.00001" "w" "0.00001" "1" "");写个文本,也是和上面一样,不知道如何处理异常。
(setq ss (ssget "X" (list '(0 . "MTEXT") (cons 8 layern))))
(setq i 0)
(while (< i (sslength ss))
(command "explode" (ssname ss i)) ;炸开
(setq i (1+ i))
)
(setq ss(ssget "x" (list '(0 . "TEXT") (cons 8 layern)))) ;把这一层的数字开头的放到“编号”层。
(setq sn(if ss (sslength ss) 0))
(setq i 0)
(while (< i sn)
(setq si(ssname ss i))
(setq wText(cdr(assoc 1 (entget si))))
(setq c1(substr wText 1 1))
(if(and(> c1 "/")(< c1 ":"))
(command "_.change" si "" "p" "la" lay1 "")
(command "_.change" si "" "p" "la" lay2 "")
)
(setq i(1+ i))
)
(setq layern "COUPLER") ;对COUPLER的层做同样的处理。
(command "_LAYER" "S" layern "")
(setq ss (ssget "X" (list '(0 . "MTEXT") (cons 8 layern))))
(setq i 0)
(while (< i (sslength ss))
(command "explode" (ssname ss i))
(setq i (1+ i))
)
(setq ss(ssget "x" (list '(0 . "TEXT") (cons 8 layern))))
(setq sn(if ss (sslength ss) 0))
(setq i 0)
(while (< i sn)
(setq si(ssname ss i))
(setq wText(cdr(assoc 1 (entget si))))
(setq c1(substr wText 1 1))
(if(and(> c1 "/")(< c1 ":"))
(command "_.change" si "" "p" "la" lay1 "")
(command "_.change" si "" "p" "la" lay2 "")
)
(setq i(1+ i))
)

(command ".LAYER" "S" "0" "") ;选择0层 炸开其他的所有多行文字。
(setq ss (ssget "X" '((0 . "MTEXT"))))
(setq i 0)
(while (< i (sslength ss))
(command "explode" (ssname ss i))
(setq i (1+ i))
) (setq ff (getfiled "请选择数据文件:" "C:/LISP" "txt" 8));读取外部数据 获取图层名称和多义线的宽度,根据这些数据把该层的线该为相应的宽度的多义线。
(setq f (open ff "r")) (while (setq lname (read-line f))
(setq wid (read-line f))
(command "_.layer" "m" lname "")
(command "line" "5,5" "5,5" "")
(setq ss (ssget "X" (list '(0 . "line,arc,*POLYLINE") (cons 8 lname))))
(setq i 0) ;
(while (< i (sslength ss))
(setq ssa-ent (ssname ss i))
(setq ent-p (cdr (assoc 0 (entget ssa-ent))))
(if (not (null ent-p)) ;
(if (or (= ent-p "POLYLINE") (= ent-p "LINE")) ;
(command "pedit" ssa-ent "y" "w" wid "j" ss "" "")
(command "pedit" ssa-ent "w" wid "j" ss "" "")
))
(setq i (1+ i))
)
)
(close f)
(command "undo" "e")
(command "zoom" "a" "") ;
(setvar "cmdecho" 1)
(princ)
)

本帖子中包含更多资源

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

x
发表于 2005-1-28 01:33:00 | 显示全部楼层
不知是否行?
  1. (defun c:test (/ ss)
  2.    (setvar "cmdecho" 0)
  3.    (command "undo" "be")
  4.    (mkla "ANT" 7)
  5.    (command "fillmode" "1")
  6.    (setq ss (ssget "X" '((0 . "MTEXT") (8 . "ANT"))))
  7.    (setq i 0)
  8.    (while (< i (sslength ss))
  9.        (command "explode" (ssname ss i))
  10.        (setq i (1+ i))
  11.    )
  12.    (mkla "编号" 7)
  13.    (mkla "COUPLER" 7)
  14.    (mkla "DIVIDER" 7)
  15.    (command "_mtext" "5,5" "h" "0.00001" "w" "0.00001" "1" "")
  16.           ;写个文本,也是和上面一样,不知道如何处理异常。
  17.    (setq ss (ssget "X" (list '(0 . "MTEXT") (cons 8 "DIVIDER"))))
  18.    (setq i 0)
  19.    (while (< i (sslength ss))
  20.        (command "explode" (ssname ss i))
  21.        (setq i (1+ i))
  22.    )
  23.    (setq ss (ssget "x" (list '(0 . "TEXT") (cons 8 "DIVIDER"))))
  24.    (setq  sn (if ss
  25.            (sslength ss)
  26.            0
  27.        )
  28.    )
  29.    (setq i 0)
  30.    (while (< i sn)
  31.        (setq si (ssname ss i))
  32.        (setq wText (cdr (assoc 1 (entget si))))
  33.        (setq c1 (substr wText 1 1))
  34.        (if  (and (> c1 "/") (< c1 ":"))
  35.            (command "_.change" si "" "p" "la" lay1 "")
  36.            (command "_.change" si "" "p" "la" lay2 "")
  37.        )
  38.        (setq i (1+ i))
  39.    )
  40.    (mkla "COUPLER" 7)
  41.    (setq ss (ssget "X" (list '(0 . "MTEXT") (cons 8 layern))))
  42.    (setq i 0)
  43.    (while (< i (sslength ss))
  44.        (command "explode" (ssname ss i))
  45.        (setq i (1+ i))
  46.    )
  47.    (setq ss (ssget "x" (list '(0 . "TEXT") (cons 8 layern))))
  48.    (setq  sn (if ss
  49.            (sslength ss)
  50.            0
  51.        )
  52.    )
  53.    (setq i 0)
  54.    (while (< i sn)
  55.        (setq si (ssname ss i))
  56.        (setq wText (cdr (assoc 1 (entget si))))
  57.        (setq c1 (substr wText 1 1))
  58.        (if  (and (> c1 "/") (< c1 ":"))
  59.            (command "_.change" si "" "p" "la" lay1 "")
  60.            (command "_.change" si "" "p" "la" lay2 "")
  61.        )
  62.        (setq i (1+ i))
  63.    )
  64.    (command ".LAYER" "S" "0" "")
  65.    (setq ss (ssget "X" '((0 . "MTEXT"))))
  66.    (setq i 0)
  67.    (while (< i (sslength ss))
  68.        (command "explode" (ssname ss i))
  69.        (setq i (1+ i))
  70.    )
  71.    (setq ff (getfiled "请选择数据文件:" "C:/LISP" "txt" 8))
  72.    ;;读取外部数据 获取图层名称和多义线的宽度,根据这些数据把该层的线该为相应的宽度的多义线。
  73.    (setq f (open ff "r"))
  74.    (while (setq lname (read-line f))
  75.        (setq wid (read-line f))
  76.        (command "_.layer" "m" lname "")
  77.        (command "line" "5,5" "5,5" "")
  78.        (setq ss (ssget "X"
  79.            (list '(0 . "line,arc,*POLYLINE") (cons 8 lname))
  80.            )
  81.        )
  82.        (setq i 0)
  83.        (while (< i (sslength ss))
  84.            (setq ssa-ent (ssname ss i))
  85.            (setq ent-p (cdr (assoc 0 (entget ssa-ent))))
  86.            (if (not (null ent-p))
  87.   (if (or (= ent-p "POLYLINE") (= ent-p "LINE"))
  88.      (command "pedit" ssa-ent "y" "w" wid "j" ss "" "")
  89.      (command "pedit" ssa-ent "w" wid "j" ss "" "")
  90.   )
  91.            )
  92.            (setq i (1+ i))
  93.        )
  94.    )
  95.    (close f)
  96.    (command "undo" "e")
  97.    (command "zoom" "a" "")
  98.    (setvar "cmdecho" 1)
  99.    (princ)
  100. )
  101. (defun mkla (name color)
  102.    (If (= (Tblsearch "layer" name) nil)
  103.        (Command "layer" "m" name "c" color name "")
  104.        (Command "layer" "t" name "s" name "c" color name "")
  105.    )
  106. )
发表于 2005-1-28 02:02:00 | 显示全部楼层
我觉的程序能达到要求就行,没有必要刻意去瘦身.
 楼主| 发表于 2005-1-28 09:38:00 | 显示全部楼层
我只是想通过瘦身提高自己的水平,现在程序是小,如果是大的呢?谢谢楼上的指点,我看了一下,我又点明白你的意思了,谢谢你的指点。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-17 18:38 , Processed in 0.159413 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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