明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 761|回复: 1

请高手帮忙修改一下lisp

[复制链接]
发表于 2015-3-26 16:58 | 显示全部楼层 |阅读模式
;标注导线方位角及距离程序
(defun c:bzfwj();标注导线方位角及距离程序
(setq thzt (getvar "textsize"))
(setq hzt (getdist (strcat "\n 字体高度<" (rtos thzt) ">:")))
(if (= hzt nil) (setq hzt thzt))
(setvar "dimscale" hzt)
(command "style" "big" "宋体" hzt 1 "" "n" "")
(princ "\n 请选择要标注的线:")
(setq ssl (ssget))
(setvar "osmode" 0) ;关闭捕捉

(setq ns (sslength ssl))
(setq is 0)
(repeat ns
(setq sl (entget (ssname ssl is )))
(setq n (length sl))
(setq i 0)
(setq xal nil)
(if (= (cdr (assoc 0 sl)) "LWPOLYLINE")
  (progn
   (repeat n
    (setq tal (nth i sl))
    (setq ftal (nth 0 tal))
    (if (= ftal 10) (setq xal (cons (list (nth 1 tal)(nth 2 tal)) xal)))
    (setq i (+ i 1))
    (princ ftal)
   );repeat
   (setq xal (reverse xal))
   (setq n (length xal))
   (if (> n 1)
    (progn
     (setq i 0)
     (repeat (- n 1)
      (setq p1 (nth i xal))
      (setq p2 (nth (+ i 1) xal))
      (setq x1 (nth 0 p1))
      (setq x2 (nth 0 p2))
      (setq y1 (nth 1 p1))
      (setq y2 (nth 1 p2))
      (setq ss (distance p1 p2))
      (setq aa (angle p1 p2))
      (setq pmid (list (/ (+ x1 x2) 2) (/ (+ y1 y2) 2)))
      (command "text" "s" "big" "j" "bc" pmid (/ (* aa 180) 3.1415926) (dmstosdms ( hdtodms (jsfwj y1 x1 y2 x2)))  "")
      (command "text" "s" "big" "j" "tc" pmid (/ (* aa 180) 3.1415926) (rtos ss 2 3)  "")
      (setq i (+ i 1))
     );repeat
    );progn
   );if
  );progn
);if
(if (= (cdr (assoc 0 sl)) "LINE")
  (progn
   (setq p1 (cdr (assoc 10 sl)))
   (setq p2 (cdr (assoc 11 sl)))
   (setq x1 (nth 0 p1))
   (setq x2 (nth 0 p2))
   (setq y1 (nth 1 p1))
   (setq y2 (nth 1 p2))
   (setq ss (distance p1 p2))
   (setq aa (angle p1 p2))
   (setq pmid (list (/ (+ x1 x2) 2) (/ (+ y1 y2) 2)))
   (command "text" "s" "big" "j" "bc" pmid (/ (* aa 180) 3.1415926) (dmstosdms ( hdtodms (jsfwj y1 x1 y2 x2)))  "")
   (command "text" "s" "big" "j" "tc" pmid (/ (* aa 180) 3.1415926) (rtos ss 2 3)  "")
  );progn
);if
(setq is (+ is 1))
);repeat
)


(defun dmstosdms(dms)
   (setq d (fix dms))
   (setq m (fix (* 100.0 (- dms d))) )
   (setq s (* (- (* 100.0 (- dms d)) m) 100.0) )
  (if (>= s 60.0) (progn (- s 60.0) (+ m 1)))
  (if (>= m 60.0) (progn (- m 60.0) (+ d 1)))
  (strcat (rtos (fix d)2 0) "°" (rtos (fix m)2 0) "′" (rtos s 2 1) "″")
)

(defun hdtodms(tjd)
(setq jd tjd)
(setq bneg 1)
(if (< jd 0) (setq bneg -1))
(setq jd (abs (/ (* tjd 180.0) 3.1415926)))
(setq du (fix jd))
(setq fen (fix (* (- jd du) 60.0)))
(setq miao (* (- (* (- jd du) 60.0) fen) 60.0) )
(if (< (abs (- miao 60)) 0.0001)
  (progn
   (setq miao 0.0)
   (setq fen (+ fen 1))
   (if (< (abs (- fen 60)) 0.0001)
    (progn
     (setq fen 0.0)
     (setq du (+ du 1))
    )
    )
  )
)
(setq dms (* bneg (+ du (/ fen 100.0) (/ miao 10000.0))))
)

(defun jsfwj(tx1 ty1 tx2 ty2)
(setq dx (- tx2 tx1) dy (- ty2 ty1))
(if (= dx 0)
  (progn
   (if (> dy 0) (setq fwj (/ 3.1415926 2)))
   (if (< dy 0) (setq fwj (* 3 (/ 3.1415926 2))))
  )
  (setq fwj (+ (atan (/ dy dx)) (/ 3.1415926 2) (* (/ -3.1415926 2) (/ (abs dx) dx))))
)
(if (< fwj 0) (setq fwj (+ fwj (* 3.1415926 2))) (setq fwj fwj))
)

 楼主| 发表于 2015-3-26 16:59 | 显示全部楼层
这个做方位角的lisp很好用就是换到win7系统以后会出现以下错误:命令: BZFWJ 未知命令“BZFWJ”。按 F1 查看帮助。
命令: 1
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-3-29 21:33 , Processed in 0.193178 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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