找回密码
 [加入论坛]
查看: 2396|回复: 6

有用的lisp小工具集合

[复制链接]
2443725 发表于 2004-11-25 15:58 | 显示全部楼层 |阅读模式
<><FONT face=宋体>这个小程序用于选取图中的text实体,计算其数字和:</FONT></P>
<P><FONT face=宋体>;;;拾取数字求和       
(defun c:pickad        (/ ss n totn adn)
  (prompt "\n拾取数字求和: ")
  (setq        ss (ssget '((0 . "TEXT")))
        n  0
  )
  (setq totn 0.0)
  (while (setq en (ssname ss n))
    (setq adn (atof (cdr (assoc 1 (entget en)))))
    (setq totn (+ totn adn))
    (setq n (1+ n))
  )
  (princ (strcat "\n数字和: "))
  (princ totn)
  (princ)
)</FONT>
</P>
 楼主| 2443725 发表于 2004-11-25 15:58 | 显示全部楼层
<><FONT face=宋体 size=2>拾取数字和(可作减法)</FONT></P><P><FONT face=宋体 size=2>(defun c:pickad1 (/ psub1 ss totn)                ;拾取数字和(可作减法)
  (defun psub1 (ss / tot n en adn)
    (setq tot 0.0
          n   0
    )
    (while (setq en (ssname ss n))
      (setq adn (atof (cdr (assoc 1 (entget en)))))
      (setq tot        (+ tot adn)
            n        (1+ n)
      )
    )
    tot
  )

  (prompt "\n拾取数字求差: ")
  (prompt "\n请先选择被减的数字: ")
  (setq        ss   (ssget '((0 . "TEXT")))
        totn (psub1 ss)
  )
  (prompt "\n再选择要减去的数字: ")
  (setq        ss   (ssget '((0 . "TEXT")))
        totn (- totn (psub1 ss))
  )
  (princ (strcat "\n数字和: "))
  (princ totn)
  (princ)
)</FONT></P>
回复 顶 踩

使用道具 举报

 楼主| 2443725 发表于 2004-11-25 15:59 | 显示全部楼层
<><FONT face=宋体>直接修改圆角半径</B></FONT> </P><P><FONT face=宋体 size=2>改变已有的圆角半径:点选圆角弧,输入新半径值,自动重新圆角。
我用它修改过道路转角半径,还算不错:}</FONT></P><P><FONT face=宋体 size=2>;;;MRADIUS.LSP  直接修改FILLET直线半径.
;;;
;;;     v0.5  - 1998.1.25</FONT></P><P><FONT face=宋体 size=2>(defun c:mradius( / cget en ent ps1 ps2 e1 e2 r1 r2)</FONT></P><P><FONT face=宋体 size=2>  (defun cget(pt siz lnm / ss eout en ent p1 p2 n)
    (setq ss
      (ssget "c"
        (list (- (car pt) siz) (- (cadr pt) siz))
        (list (+ (car pt) siz) (+ (cadr pt) siz))
        (list '(0 . "LINE") (cons 8 lnm))
      )
    )
    (if ss (progn
      (setq n 0)
      (while (and (not eout) (setq en (ssname ss n)))
        (setq ent (entget en)
              p1 (cdr (assoc 10 ent))
              p2 (cdr (assoc 11 ent)))
        (if (or (equal p1 pt siz) (equal p2 pt siz))
          (setq eout en)) ;if
        (setq n (1+ n))
      )
    )) ;if
    eout
  ) ;CGET</FONT></P><P><FONT face=宋体 size=2>  (setvar "cmdecho" 0)
  (command "undo" "group")
(while   (setq en (car (entsel)))
  (setq ent (entget en)
        o1 (cdr (assoc 10 ent))
        lnm (cdr (assoc 8 ent))
        r1 (cdr (assoc 40 ent))
        a1 (cdr (assoc 50 ent))
        a2 (cdr (assoc 51 ent)))
  (redraw en 3)
  (if (setq ls (getreal (strcat "半径&lt;" (rtos r1 2) "&gt;: ")))
    (setq r2 ls))
  (redraw en)
;  (setq r2 2000.0)
  (if (and r2 (/= r2 r1)) (progn
    (setq ps1 (polar o1 a1 r1) ps2 (polar o1 a2 r1))
    (setq e1 (cget ps1 0.1 lnm) e2 (cget ps2 0.1 lnm))
    (if (and e1 e2) (progn
      (entdel en)
      (setvar "filletrad" r2)
      (command "fillet" (list e1 ps1) (list e2 ps2))
    )) ;if
  )) ;if
)
  (command "undo" "end")
  (princ)
)
</FONT></P>
回复 顶 踩

使用道具 举报

 楼主| 2443725 发表于 2004-11-25 16:01 | 显示全部楼层
<><FONT face=宋体 size=2>如果你做施工图设计可能会用到标注配件编号,即从某配件上引出一条直线,在直线末端画一个圆圈,在圆圈中表一个编号,以便在材料表中注明配件名称规格等,这个lisp就是做这些的,如果你有用就拿去吧,程序还比较简陋,欢迎高手完善。</FONT></P><P><FONT face=宋体 size=2>(defun biaozhu (/ a1)
   (if (or (null r0) (= r0 0)) (setq r0 100))
   (if (null h0) (setq h0 100))
   (if (or (listp s0) (null s0) (numberp s0) (= s0 "") (not (tblsearch "style" s0))) (setq s0 (getvar "textstyle")))
   (if (or (listp text0) (null text0) (= text0 "")) (setq text0 "00"))
   (setq a1 T)
      (while a1(princ "The current Radius is &lt;")
         (princ r0)
         (princ (strcat "&gt;  The current Text-style is &lt;" s0 "&gt;"  "\nThe current Text-high is &lt;"))
         (princ h0)
         (princ "&gt;")
           (initget "circle-Radius text-Stytle text-High Text")
           (setq a1 (getpoint "\ncircle-Radius/text-Stytle/text-High/Text/&lt;startpoint&gt;:"))
   
       (if a1
         (cond ((= a1 "circle-Radius") (cradius))
                ((= a1 "text-Stytle")    (tstytle))
                ((= a1 "text-High")      (thigh))
                ((= a1 "Text")           (textx))
                (T                      (drawline))
                )
           (setq a1 nil)
       )
      )
)
</FONT></P>
回复 顶 踩

使用道具 举报

 楼主| 2443725 发表于 2004-11-25 16:02 | 显示全部楼层
<><b>一个螺旋线的 </b></P><P><FONT face=宋体 size=2>程序有一个小功能:记忆上次输入的数据。这样会方便很多。</FONT></P><P><FONT face="Courier New">(defun c:rol1( / r1 r2 high hi stps p0 p1 p2 ang i hia)
  (command "undo" "group")
  (princ "\n绘制弹簧线....")
  (or #rol1_dat (setq #rol1_dat '(1000.0 3000.0 72 24)))
  (mapcar 'set '(r1 high stps stpp) #rol1_dat)
  (if (setq ls (getint (strcat "\n每圈步数&lt;" (itoa stpp) "&gt;: "))) (setq stpp ls))
  (setq ctr (getpoint "\n起点圆心: "))
  (if (setq ls (getdist ctr (strcat "\n半径&lt;" (rtos r1 2 2) "&gt;: "))) (setq r1 ls))
  (if (setq ls (getdist ctr (strcat "\n螺距&lt;" (rtos high 2 2) "&gt;: "))) (setq high ls))
  (if (setq ls (getint (strcat "\n总步数&lt;" (itoa stps) "&gt;: "))) (setq stps ls))
  (setq ang 0
        p1 (polar ctr ang r1)
        hia (/ high stpp)
        i 0)
  (command "3dpoly" p1)
  (repeat stps
    (setq ang (+ ang (/ pi 12.0))
          i (1+ i)
          hi (* i hia))
    (command (mapcar '+ (polar ctr ang r1) (list 0 0 (* i hia))))
  ) ;repeat
  (command "")  
  (setq #rol1_dat (list r1 high stps stpp))
  (command "undo" "end")
  (princ)
)</FONT></P>
回复 顶 踩

使用道具 举报

 楼主| 2443725 发表于 2004-11-25 16:03 | 显示全部楼层
<><FONT face=宋体 size=2>点选实体进行绘制。</B> </FONT></P><P><FONT face=宋体 size=2>这个程序基于这样的想法:
作图的时候,要作的对象在图中已有同类的实体,则点取这个同类的实体,程序根据其类型调用相应的绘制命令。
更有意义的是:程序会自动匹配颜色、线形、图层等参数,省去了许多转换操作。</FONT></P><P><FONT face=宋体 size=2>;;;LCMD.LSP
;;;</FONT></P><P><FONT face=宋体 size=2>;;;</FONT></P><P><FONT face=宋体 size=2>(defun c:lcmd( / ss en nl nc nlt ladd n cc ent nthk ntp)
  (setvar "cmdecho" 0) </FONT></P><P><FONT face=宋体 size=2>;;;主程序</FONT></P><P><FONT face=宋体 size=2>  (setq en (entsel "\n请选择目标实体: "))
  (if en (progn
    (setq eent (entget (car en))
          ntp (cdr (assoc 0 eent))
          nc (cdr (assoc 62 eent))            ;颜色
          nlt (cdr (assoc 6 eent))            ;线型
          nl (cdr (assoc 8 eent))             ;层
          nthk (cdr (assoc 39 eent))          ;厚度
          nelv (caddr (trans (cdr (assoc 10 eent)) 0 1))        ;高度
    )
    (if nc (setvar "cecolor" nc) (setvar "cecolor" "bylayer"))
    (if nlt (setvar "celtype" nlt) (setvar "celtype" "bylayer"))
    (setvar "clayer" nl)
    (cond
      ((= ntp "LINE") (command "line"))
      ((= ntp "POLYLINE") (command "pline"))
      ((= ntp "ARC") (command "arc"))
      ((= ntp "3DFACE") (command "3dface"))
      ((= ntp "SOLID") (command "solid"))
      ((= ntp "INSERT") (command "insert"))
      ((= ntp "CIRCLE") (command "circle"))
      ((= ntp "TEXT")
       (setvar "textstyle" (cdr (assoc 7 eent)))
       (setvar "textsize" (cdr (assoc 40 eent)))
       (command "text")
      )
      ((= ntp "DIMENSION")
      )
      ((= ntp "INSERT")
       (setq nin (cdr (assoc 2 eent)))
       (setvar "isname" nin)
       (command "insert")
      )
      (t)
    ) ;cond
   ) ;progn
  )  ;if</FONT></P><P><FONT face=宋体 size=2>  (princ)
)</FONT></P><P><FONT face=宋体 size=2></FONT> </P>
回复 顶 踩

使用道具 举报

slyjgrgs 发表于 2005-6-1 06:52 | 显示全部楼层
不错!挺实用!
回复 顶 踩

使用道具 举报

您需要登录后才可以回帖 登录 | [加入论坛]

本版积分规则

手机版|化工技术网- 赠人玫瑰 手有余香 ( 苏ICP备14035884号 )

GMT+8, 2026-12-1 16:45

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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