明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 8772|回复: 28

请高人修改一个“快速标注线段的长度、方位角”的好程序

  [复制链接]
发表于 2012-3-2 10:23 | 显示全部楼层 |阅读模式
本帖最后由 xk100 于 2012-3-2 11:42 编辑

我还不会编程序,网上收集了个“快速标注线段的长度、方位角”的好程序。现在想把它一分为二,改成快速标注线段的长度和快速标注线段方位角的两个独立的程序。以下为原程序代码,恳请高人给予帮助!
-----------------------------------------
(defun c:jlfwj()
(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))
(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)) "°" (rtos (fix m)) "′" (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))
)



发表于 2022-11-5 20:22 | 显示全部楼层
用不了,可能高版本还要适配
 楼主| 发表于 2012-3-2 11:44 | 显示全部楼层
敬请高手出手相助,先谢过了!
发表于 2012-3-2 18:35 | 显示全部楼层
(defun c:jlfwj (/ aa ftal hzt i is m n ns p1 p2 pmid sl ss ssl tal thzt x1 x2 xal y1 y2)
  (setvar "cmdecho" 0)
  (setq thzt (getvar "textsize"))
  (if (null mosbak)
    (setq mosbak 1)
  )
  (if (setq m (getint (strcat "\n 要标注[1.线长和方位角/2.线长/3.方位角]:<" (itoa mosbak) ">")))
    (setq mosbak m)
  )
  (setq hzt (getdist (strcat "\n 字体高度<" (rtos thzt) ">:")))
  (if (= hzt nil)
    (setq hzt thzt)
  )
  (command ".UNDO" "BE")
  (setvar "dimscale" hzt)
  (command "style" "big" "宋体" hzt 1 "" "n" "")
  (princ "\n 请选择要标注的线:")
  (setq ssl (ssget))
  (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))
        )                               ; 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)))
              (if (or
                    (= mosbak 1)
                    (= mosbak 3)
                  )
                (command "text" "s" "big" "j" "bc" pmid (/ (* aa 180) 3.1415926) (dmstosdms (hdtodms (jsfwj y1 x1 y2 x2))))
              )
              (if (or
                    (= mosbak 1)
                    (= mosbak 2)
                  )
                (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)))
        (if (or
              (= mosbak 1)
              (= mosbak 3)
            )
          (command "text" "s" "big" "j" "bc" pmid (/ (* aa 180) 3.1415926) (dmstosdms (hdtodms (jsfwj y1 x1 y2 x2))))
        )
        (if (or
              (= mosbak 1)
              (= mosbak 2)
            )
          (command "text" "s" "big" "j" "tc" pmid (/ (* aa 180) 3.1415926) (rtos ss 2 3))
        )
      )                                       ; progn
    )                                       ; if
    (setq is (+ is 1))
  )                                       ; repeat
  (command ".UNDO" "E")
  (princ)
)
(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)) "°" (rtos (fix m)) "′" (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)
  )
)

评分

参与人数 1明经币 +1 收起 理由
vlisp2012 + 1 赞一个!

查看全部评分

发表于 2012-3-2 19:47 | 显示全部楼层
langjs:
很喜欢你的程序啊,多谢了!!!!!
 楼主| 发表于 2012-3-2 22:54 | 显示全部楼层
langjs 发表于 2012-3-2 18:35
(defun c:jlfwj (/ aa ftal hzt i is m n ns p1 p2 pmid sl ss ssl tal thzt x1 x2 xal y1 y2)
  (setvar  ...

试过了,比原来的程序多2个选项,非常好用。感谢您无私的帮助!衷心地祝福您!
发表于 2012-4-13 22:43 | 显示全部楼层
命令: jlfwj
字体高度<0.200>:
字体文件不存在。0.200000
未知命令“JLFWJ”。按 F1 查看帮助。
1
未知命令“JLFWJ”。按 F1 查看帮助。
未知命令“N”。按 F1 查看帮助。
未知命令“JLFWJ”。按 F1 查看帮助
发表于 2012-4-14 00:25 | 显示全部楼层
不知道怎么用,求解.
发表于 2012-4-29 13:12 | 显示全部楼层
2008下能通过,在2004下出现下列代码:
命令: jlfwj
要标注[1.线长和方位角/2.线长/3.方位角]:<1>2
字体高度<0.2000>:2.5
字体文件不存在。2.500000
未知命令“JLFWJ”。按 F1 查看帮助。
1
未知命令“JLFWJ”。按 F1 查看帮助。
未知命令“N”。按 F1 查看帮助。
未知命令“JLFWJ”。按 F1 查看帮助。
请langis看下,看能在CAD2004下如何通过?多谢了
发表于 2012-5-15 12:56 | 显示全部楼层
非常感谢哦
发表于 2012-6-20 14:43 | 显示全部楼层
很不错的程序。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-18 16:03 , Processed in 0.227272 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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