明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2352|回复: 9

可以自动改变直线圆等的线形比例 ,但不能改变矩形及多段线的 请修改一下

[复制链接]
发表于 2010-4-30 23:40:00 | 显示全部楼层 |阅读模式

大家好  我这有一个非常好的LISP程序  可以自动改变直线,圆等的线形比例   但不能改变矩形及多段线的的   哪位大大修改一下

 

(defun c:df ()    ;自動變換成適當比例的虛線
  (ltchange "dashed"  3 "bylayer")
  (princ)
)

(defun ltchange (type1 scale color /  oce   lin   n    nam  tab
   pt1   pt2   x1    x2  y1    y2    len   leg  sca
   otyp  ocol  osca  col  typ   lts   rad
  )   ;自動變換成適當比例的中心線
  (setq oce (getvar "cmdecho")
 lts (getvar "ltscale")
  ) ;_ end of setq
  (setvar "cmdecho" 0)
  (setq n 0)
  (print
    (strcat "Select object change to " type1 ":")
  ) ;_ end of print
  (setq lin (ssget '((-4 . "<OR")
       (0 . "LINE")
       (0 . "CIRCLE")
       (0 . "ELLIPSE")
       (0 . "ARC")
       (0 . "polyline")
       (-4 . "OR>")
      )
     ) ;_ end of ssget
  )     ;end setq
  (if (not lin)
    (progn

      (alert "\nNo selection!")
      (exit)
    ) ;_ end of progn
  )     ;end if
  (repeat (sslength lin)
    (setq nam (ssname lin n))
    (setq tab (entget nam))
;;;;;;;;;;circle
    (if (= (cdr (assoc 0 tab)) "CIRCLE")
      (progn
 (setq rad (cdr (assoc 40 tab)))
 (setq len (* 2 (* 3.14 rad)))
      )     ;如是圓實體取周長為"len"
;;;;;;;;;;ARC
      (if (= (cdr (assoc 0 tab)) "ARC")
 (progn
   (setq rad (cdr (assoc 40 tab)))
   (setq len (* 3.14 rad))
 )    ;end progn;如是圓弧取其圓周長半

;;;;;;;;;;ellipse
    (if (= (cdr (assoc 0 tab)) "ellipse")
      (progn
 (setq rad (cdr (assoc 40 tab)))
 (setq len (* 2 (* 3.14 rad)))
      )
;;;;;;;;;LINE
 (progn
   (setq pt1 (cdr (assoc 10 tab))
  pt2 (cdr (assoc 11 tab))
  len (distance pt1 pt2)
   )    ;end setq
 )    ;end progn
      )     ;end if  
    )
   );end if

    (cond ((and (> len 0) (<= len 2))
    (setq leg 2)
   )
   ((and (> len 2) (<= len 5))
    (setq leg 6)
   )
   ((and (> len 5) (<= len 30))
    (setq leg 20)
   )
   ((and (> len 30) (<= len 50))
    (setq leg 40)
   )
   ((and (> len 50) (<= len 100))
    (setq leg 75)
   )
   ((> len 100)
    (setq leg 100)
   )
    )     ;end cond
    (setq sca (/ leg scale lts 2))

    (command "-linetype" "l" type1 "acad.lin" "" "")
    (command "change" nam "" "p" "c" color "lt" type1 "s" SCA "") ;_ end of command
 ;_ end of command
 ;_ end of command
    (setq n (+ n 1))
  )     ;end repeat
  (setvar "cmdecho" oce)
  (princ)
) ;_ end of defun

发表于 2010-5-1 10:14:00 | 显示全部楼层
本帖最后由 作者 于 2010-5-1 20:42:48 编辑
  1. (defun c:df ()    ;自動變換成適當比例的虛線
  2.   (ltchange "dashed" 3 "bylayer")
  3.   (princ)
  4. )
  5. (defun ltchange (type1 scale color / oce lts lin n nam len leg sca) ;自動變換成適當比例的中心線
  6. (setq oce (getvar "cmdecho")
  7.        lts (getvar "ltscale"))
  8. (setvar "cmdecho" 0)
  9. (setq n 0)
  10. (princ (strcat "\nSelect object change to " type1 ":"))
  11. (if (setq lin (ssget '((0 . "ARC,CIRCLE,*LINE,ELLIPSE")))) (progn
  12.   (repeat (sslength lin)
  13.    (setq nam (ssname lin n))
  14.    (command "lengthen" nam "")
  15.    (setq LEN (getvar "perimeter"))
  16.    (cond
  17.     ((> 2 len 0) (setq leg 2))
  18.     ((> 5 len 2) (setq leg 6))
  19.     ((> 30 len 5) (setq leg 20))
  20.     ((> 50 len 30) (setq leg 40))
  21.     ((> 100 len 50) (setq leg 75))
  22.     ((> len 100) (setq leg 100))
  23.    );end cond
  24.    (setq sca (/ leg scale lts 2))
  25.    (command "-linetype" "l" type1 "acad.lin" "" "")
  26.    (command "change" nam "" "p" "c" color "lt" type1 "s" SCA "") ;_ end of command
  27.    (setq n (1+ n))
  28.   );end repeat
  29. ));end if
  30. (setvar "cmdecho" oce)
  31. (princ)
  32. );_ end of defun
 楼主| 发表于 2010-5-1 10:26:00 | 显示全部楼层
谢啦  但我试了下说是错误参数太多  不能用啊
发表于 2010-5-1 20:43:00 | 显示全部楼层

二楼已改,再试试。

 楼主| 发表于 2010-5-2 00:14:00 | 显示全部楼层
还是不行啊,df \nSelect object change to dashed:; 错误: 参数太多
是不是版本不同啊  我是CAD2004的     把矩形及多段线打散也可以的

帮忙再改下
发表于 2010-5-2 21:29:00 | 显示全部楼层

我是在2004下调试通过的,没问题呀!

 楼主| 发表于 2010-5-2 22:51:00 | 显示全部楼层
(defun c:df ()    ;自動變換成適當比例的虛線
  (ltchange "dashed" 3 "bylayer")
  (princ)
)
(defun ltchange (type1 scale color / oce lts lin n nam len leg sca) ;自動變換成適當比例的中心線
(setq oce (getvar "cmdecho")
       lts (getvar "ltscale"))
(setvar "cmdecho" 0)
(setq n 0)
(princ (strcat "\\nSelect object change to " type1 ":"))
(if (setq lin (ssget \'((0 . "ARC,CIRCLE,*LINE,ELLIPSE")))) (progn
  (repeat (sslength lin)
   (setq nam (ssname lin n))
   (command "lengthen" nam "")
   (setq LEN (getvar "perimeter"))
   (cond
    ((&gt; 2 len 0) (setq leg 2))
    ((&gt; 5 len 2) (setq leg 6))
    ((&gt; 30 len 5) (setq leg 20))
    ((&gt; 50 len 30) (setq leg 40))
    ((&gt; 100 len 50) (setq leg 75))
    ((&gt; len 100) (setq leg 100))
   );end cond
   (setq sca (/ leg scale lts 2))
   (command "-linetype" "l" type1 "acad.lin" "" "")
   (command "change" nam "" "p" "c" color "lt" type1 "s" SCA "") ;_ end of command
   (setq n (1+ n))
  );end repeat
));end if
(setvar "cmdecho" oce)
(princ)
);_ end of defun


是这样吧  我怎么试就是不行呢


[此贴子已经被作者于2010-5-1 20:42:48编辑过]
 楼主| 发表于 2010-5-3 08:48:00 | 显示全部楼层
谢啦 我又试了下 可以了  ssget \'((0 . "ARC,CIRCLE,*LINE,ELLIPSE"))  把里面的\去掉就可以了
发表于 2010-5-7 11:41:00 | 显示全部楼层
还是不行啊,df \nSelect object change to dashed:; 错误: 参数太多
是不是版本不同啊  我是CAD2004的     把矩形及多段线打散也可以的

帮忙再改下
发表于 2010-5-7 21:12:00 | 显示全部楼层
回9楼:看8楼的改动。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-2-27 20:06 , Processed in 0.196977 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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