明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3008|回复: 8

[已解答] 任意四边形,标注辅助线尺寸,列出公式。求帮忙,谢谢啦

[复制链接]
发表于 2014-8-26 21:10 | 显示全部楼层 |阅读模式
10明经币
本帖最后由 Gu_xl 于 2014-8-26 21:41 编辑

目标是对于任意四边形,会自动做辅助线并自动标注尺寸接着自动列出公式
目前代码已经实现做辅助线(感谢cad高手:q2 的无私奉献)

  1. (defun c:tt ( / a b e l l1 l2 p pt1 pt2 pts px x y)
  2. (vl-load-com)
  3. (defun gpts (e) (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e))))
  4. (defun mkline (pt1 pt2) (entmakex (list '(0 . "LINE") (cons 10 pt1) (cons 11 pt2))))
  5. (setq p (getpoint))
  6. (vl-cmdf "bpoly" p "")
  7. (setq e (entlast)
  8.   pts (gpts e)
  9.   l (list (list (car pts) (caddr pts)) (list (cadr pts) (cadddr pts)))
  10.   l (vl-sort l '(lambda (x y) (> (distance (car x) (cadr x)) (distance (car y) (cadr y))) ) )
  11.   l1 (car l)
  12.   l2 (cadr l)
  13.   a (mkline (car l1) (cadr l1))
  14.   b (mkline (setq px (car l2)) (vlax-curve-getClosestPointTo a px))
  15.   b (mkline (setq px (cadr l2)) (vlax-curve-getClosestPointTo a px))
  16. )
  17. (entdel e)
  18. )


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

最佳答案

发表于 2014-8-26 21:10 | 显示全部楼层
本帖最后由 edata 于 2014-8-30 16:38 编辑



  1. (defun c:tt(/ ss lst en ANGH1 ANGH2 ANGW1A ANGW1B ANGW2A ANGW2B
  2.       H1 H2 P1 P2 P2C P3 P4 P4C PTH1 PTH2 PTW1A PTW1B PTW2A PTW2B STR1 TXTPT W1A W1B W2A W2B)
  3.   (or font_hh (setq font_hh 2.5))
  4.   (setq font_hh(cond((getdist (strcat "\n输入文字高度<"(rtos font_hh 2 2) ">:")))(font_hh)))
  5.   (if(setq ss(ssget '((0 . "LWPOLYLINE"))))   
  6.     (while(setq en(ssname ss 0))
  7.       (redraw en 3)
  8.       (setq lst(mapcar 'cdr (vl-remove-if-not ''((x)(= (car x) 10)) (entget en))))
  9.       (mapcar 'set '(p1 p2 p3 p4) lst)
  10.       (setq p2c(PerToLine p2 p1 p3)
  11.       p4c(PerToLine p4 p1 p3)
  12.       w1a(distance p1 p4c)
  13.       h1(distance p4c p4)
  14.       w1b(distance p4c p3)
  15.       w2a(distance p2c p1)
  16.       h2(distance p2c p2)
  17.       w2b(distance p2c p3)
  18.       angw1a(angle p1 p4c)
  19.       angh1(angle p4c p4)
  20.       angw1b(angle p4c p3)
  21.       angw2a(angle p2c p1)
  22.       angh2(angle p2c p2)
  23.       angw2b(angle p3 p2c)      
  24.       ptw1a(polar (sk_m2p p1 p4c) (+ angw1a (* pi 0.5)) (* font_hh 0.25))
  25.       pth1(polar (sk_m2p p4c p4) (+ angh1 (* pi 0.5))(* font_hh 0.25))
  26.       ptw1b(polar (sk_m2p p4c p3) (+ angw1b (* pi 0.5)) (* font_hh 0.25))
  27.       ptw2a(polar (sk_m2p p2c p1) (+ angw2a (* pi 0.5)) (* font_hh 0.25))
  28.       pth2(polar (sk_m2p p2c p2)(+ angh2 (* pi 0.5)) (* font_hh 0.25))
  29.       ptw2b(polar (sk_m2p p2c p3)  (+ angw2b (* pi 0.5)) (* font_hh 0.25))
  30.       )
  31.       (entmake (list '(0 . "line")(cons 10 p1)(cons 11 p3)))
  32.       (entmake (list '(0 . "line")(cons 10 p2)(cons 11 p2c)))
  33.       (entmake (list '(0 . "line")(cons 10 p4)(cons 11 p4c)))
  34.       (entmake (list '(0 . "TEXT")
  35.          (cons 1 (rtos w1a 2 2))         
  36.          (cons 73 (if (and (< angw1a (* pi 1.5))(> angw1a (* pi 0.5))) 3 0))
  37.          (cons 72 1)
  38.          (cons 10 ptw1a)
  39.          (cons 11 ptw1a)
  40.          (cons 40 font_hh)
  41.          (cons 50 (if (and (< angw1a (* pi 1.5))(> angw1a (* pi 0.5))) (+ angw1a pi) angw1a))
  42.          )
  43.       )
  44.       
  45.       (entmake (list '(0 . "TEXT")
  46.          (cons 1 (rtos h1 2 2))         
  47.          (cons 73 (if (and (< angh1 (* pi 1.5))(> angh1 (* pi 0.5))) 3 0))
  48.          (cons 72 1)
  49.          (cons 10 pth1)
  50.          (cons 11 pth1)
  51.          (cons 40 font_hh)
  52.          (cons 50 (if (and (< angh1 (* pi 1.5))(> angh1 (* pi 0.5))) (+ angh1 pi) angh1))
  53.          )
  54.       )
  55.       (entmake (list '(0 . "TEXT")
  56.          (cons 1 (rtos w1b 2 2))         
  57.          (cons 73 (if (and (< angw1b (* pi 1.5))(> angw1b (* pi 0.5))) 3 0))
  58.          (cons 72 1)
  59.          (cons 10 ptw1b)
  60.          (cons 11 ptw1b)
  61.          (cons 40 font_hh)
  62.          (cons 50 (if (and (< angw1b (* pi 1.5))(> angw1b (* pi 0.5))) (+ angw1b pi) angw1b))
  63.          )
  64.       )
  65.       (entmake (list '(0 . "TEXT")
  66.          (cons 1 (rtos w2a 2 2))         
  67.          (cons 73 (if (and (< angw2a (* pi 1.5))(> angw2a (* pi 0.5))) 3 0))
  68.          (cons 72 1)
  69.          (cons 10 ptw2a)
  70.          (cons 11 ptw2a)
  71.          (cons 40 font_hh)
  72.          (cons 50 (if (and (< angw2a (* pi 1.5))(> angw2a (* pi 0.5))) (+ angw2a pi) angw2a))
  73.          )
  74.       )
  75.       (entmake (list '(0 . "TEXT")
  76.          (cons 1 (rtos h2 2 2))         
  77.          (cons 73 (if (and (< angh2 (* pi 1.5))(> angh2 (* pi 0.5))) 3 0))
  78.          (cons 72 1)
  79.          (cons 10 pth2)
  80.          (cons 11 pth2)
  81.          (cons 40 font_hh)
  82.          (cons 50 (if (and (< angh2 (* pi 1.5))(> angh2 (* pi 0.5))) (+ angh2 pi) angh2))
  83.          )
  84.       )
  85.       (entmake (list '(0 . "TEXT")
  86.          (cons 1 (rtos w2b 2 2))         
  87.          (cons 73 (if (and (< angw2b (* pi 1.5))(> angw2b (* pi 0.5))) 3 0))
  88.          (cons 72 1)
  89.          (cons 10 ptw2b)
  90.          (cons 11 ptw2b)
  91.          (cons 40 font_hh)
  92.          (cons 50 (if (and (< angw2b (* pi 1.5))(> angw2b (* pi 0.5))) (+ angw2b pi) angw2b))
  93.          )
  94.       )
  95.       (setq str1(strcat "(" (rtos w1a 2 2) "+" (rtos w1b 2 2) ")*" (rtos h1 2 2)"/2+"
  96.       "(" (rtos w2a 2 2) "+" (rtos w2b 2 2) ")*" (rtos h2 2 2)"/2"))
  97.       (if(setq txtpt(getpoint "\n指定文字放置点:"))
  98.   (entmake (list '(0 . "TEXT") (cons 1 str1) (cons 10 txtpt)(cons 11 txtpt)(cons 72 1)(cons 73 2) (cons 40 font_hh)))
  99.   )
  100.       (redraw en 4)
  101.       (setq ss (ssdel en ss))
  102.       )   
  103.     )
  104.   (princ)
  105.   )
  106. (defun sk_m2p(p1 p2 / x y)(mapcar'(lambda(x y)(* 0.5 (+ x y))) p1 p2))
  107. ;;;计算cp到p1 p2的垂足点
  108. (defun PerToLine  (cp p1 p2 / norm)
  109.   (setq        norm (mapcar '- p2 p1)
  110.         p1   (trans p1 0 norm)
  111.         cp   (trans cp 0 norm)
  112.         )
  113.   (trans (list (car p1) (cadr p1) (caddr cp)) norm 0)
  114.   )

本帖子中包含更多资源

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

x

评分

参与人数 1明经币 +1 收起 理由
flytoday + 1 很给力!

查看全部评分

回复

使用道具 举报

发表于 2014-8-26 22:02 | 显示全部楼层

本帖子中包含更多资源

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

x
回复

使用道具 举报

 楼主| 发表于 2014-8-26 22:11 | 显示全部楼层
linjian257 发表于 2014-8-26 22:02

只发图 不发代码 是要收费的吧?呵呵
回复

使用道具 举报

 楼主| 发表于 2014-8-26 22:13 | 显示全部楼层
厉害厉害 !可惜没有代码啊,我也不能使用。求大神帮忙
回复

使用道具 举报

发表于 2014-8-27 09:57 | 显示全部楼层
linjian257
果然很牛哈
回复

使用道具 举报

发表于 2014-8-27 16:43 | 显示全部楼层
没实际意义。。。又是任意多边形才好~~
回复

使用道具 举报

 楼主| 发表于 2014-8-27 17:13 | 显示全部楼层
edata 发表于 2014-8-27 13:49

亲爱的大神 ,能共享一下源代码吗?
回复

使用道具 举报

发表于 2017-11-18 15:50 | 显示全部楼层
本帖最后由 song宋_74729 于 2017-11-18 15:57 编辑

标注参考线尺寸,列出公式 平方米
麻烦老师 
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-20 05:31 , Processed in 0.232689 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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