明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 597|回复: 13

[提问] 连续画三个矩形 后面高度值 怎么就会变不知道问题在什么地方

[复制链接]
发表于 2019-5-16 22:17 | 显示全部楼层 |阅读模式
  1. (defun c:ty ()
  2.   (initget 7)
  3.   (setq p1 (getpoint "第一点:"))
  4.            (setq p2  (getpoint p1 "\n**第二点:"))
  5.   (setq h (getdist "\n**输入宽度:"))
  6.    (setq w (getdist "\n**输入长度:"))
  7.   (setq w1 (getdist "\n**输入长度:"))
  8.   (setq w2 (getdist "\n**输入长度:"))

  9.     (setq ang (angle p1 p2) l (distance p1 p2))
  10.     (entmake
  11.       (list
  12.         '(0 . "LWPOLYLINE")
  13.         '(100 . "AcDbEntity")
  14.         '(100 . "AcDbPolyline")
  15.         '(90 . 4)
  16.         '(70 . 1)
  17.         '(43 . 0.0)
  18.         '(38 . 0.0)
  19.         '(39 . 0.0)
  20.         (cons 10 (trans (setq p(polar p1 (- ang (* 0.5 pi)) (* w))) 1 0))
  21.         (cons 10 (trans (setq p (polar p ang h)) 1 0))
  22.         (cons 10 (trans (setq p (polar p (+ ang (* 0.5 pi)) w)) 1 0))
  23.         (cons 10 (trans (setq p (polar p (+ pi ang) h)) 1 0))
  24.         )
  25.       )
  26.   
  27.     (setq pl1 (trans (setq p(polar p1 (- ang (* 0.5 pi)) (* w))) 1 0))
  28.         (setq pl2 (trans (setq p (polar p ang h)) 1 0))
  29.         (setq pl3 (trans (setq p (polar p (+ ang (* 0.5 pi)) w)) 1 0))
  30.         (setq pl4 (trans (setq p (polar p (+ pi ang) h)) 1 0))
  31.   (entmake
  32.       (list
  33.         '(0 . "LWPOLYLINE")
  34.         '(100 . "AcDbEntity")
  35.         '(100 . "AcDbPolyline")
  36.         '(90 . 4)
  37.         '(70 . 1)
  38.         '(43 . 0.0)
  39.         '(38 . 0.0)
  40.         '(39 . 0.0)
  41.         (cons 10 (trans (setq p(polar pl3 (- ang (* 0.5 pi)) (* w1))) 1 0))
  42.         (cons 10 (trans (setq p (polar p ang h)) 1 0))
  43.         (cons 10 (trans (setq p (polar p (+ ang (* 0.5 pi)) w1)) 1 0))
  44.         (cons 10 (trans (setq p (polar p (+ pi ang) h)) 1 0))
  45.         )
  46.       )
  47.   (setq pl5 (trans (setq p(polar pl3 (- ang (* 0.5 pi)) (* w1))) 1 0))
  48.         (setq pl6 (trans (setq p (polar p ang h)) 1 0))
  49.         (setq pl7 (trans (setq p (polar p (+ ang (* 0.5 pi)) w1)) 1 0))
  50.         (setq pl8 (trans (setq p (polar p (+ pi ang) h)) 1 0))
  51.   (entmake
  52.       (list
  53.         '(0 . "LWPOLYLINE")
  54.         '(100 . "AcDbEntity")
  55.         '(100 . "AcDbPolyline")
  56.         '(90 . 4)
  57.         '(70 . 1)
  58.         '(43 . 0.0)
  59.         '(38 . 0.0)
  60.         '(39 . 0.0)
  61.         (cons 10 (trans (setq p(polar pl7 (- ang (* 0.5 pi)) (* w2))) 1 0))
  62.         (cons 10 (trans (setq p (polar p ang h)) 1 0))
  63.         (cons 10 (trans (setq p (polar p (+ ang (* 0.5 pi)) w2)) 1 0))
  64.         (cons 10 (trans (setq p (polar p (+ pi ang) h)) 1 0))
  65.         )
  66.       )
  67.   
  68.     )

ty  
4.28 h
0.92 w
2.39 w1
4.28 w2
3个矩形 4.28*0.92;2.39*0.92  4.28*0.92
为啥后面0.92 w 会变  w1值也不对


发表于 2019-5-17 16:34 | 显示全部楼层
本帖最后由 satan421 于 2019-5-17 16:35 编辑
youyou3810 发表于 2019-5-17 15:06
4.28*0.92;2.39*0.92  4.28*0.92 是这样三个不同宽度矩形

;;用下面的代码,依次输入0.92 4.28 2.39 4.28

  1. (defun c:ty ()
  2.   (initget 7)
  3.   (setq p1 (getpoint "第一点:"))
  4.   (setq p2  (getpoint p1 "\n**第二点:"))
  5.   (setq h (getdist "\n**输入宽度:"))
  6.   (setq w (getdist "\n**输入长度:"))
  7.   (setq w1 (getdist "\n**输入长度:"))
  8.   (setq w2 (getdist "\n**输入长度:"))

  9.   (setq ang (angle p1 p2) l (distance p1 p2))
  10.   (entmake
  11.     (list
  12.       '(0 . "LWPOLYLINE")
  13.       '(100 . "AcDbEntity")
  14.       '(100 . "AcDbPolyline")
  15.       '(90 . 4)
  16.       '(70 . 1)
  17.       '(43 . 0.0)
  18.       '(38 . 0.0)
  19.       '(39 . 0.0)
  20.       (cons 10 (trans (setq p (polar p1 (- ang (* 0.5 pi)) (* h))) 1 0))
  21.       (cons 10 (trans (setq p (polar p ang w)) 1 0))
  22.       (cons 10 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
  23.       (cons 10 (trans (setq p (polar p (+ pi ang) w)) 1 0))
  24.     )
  25.   )

  26.   (setq pl1 (trans (setq p(polar p1 (- ang (* 0.5 pi)) (* h))) 1 0))
  27.   (setq pl2 (trans (setq p (polar p ang w)) 1 0))
  28.   (setq pl3 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
  29.   (setq pl4 (trans (setq p (polar p (+ pi ang) w)) 1 0))
  30.   (entmake
  31.       (list
  32.         '(0 . "LWPOLYLINE")
  33.         '(100 . "AcDbEntity")
  34.         '(100 . "AcDbPolyline")
  35.         '(90 . 4)
  36.         '(70 . 1)
  37.         '(43 . 0.0)
  38.         '(38 . 0.0)
  39.         '(39 . 0.0)
  40.         (cons 10 (trans (setq p (polar pl3 (- ang (* 0.5 pi)) (* h))) 1 0))
  41.         (cons 10 (trans (setq p (polar p ang w1)) 1 0))
  42.         (cons 10 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
  43.         (cons 10 (trans (setq p (polar p (+ pi ang) w1)) 1 0))
  44.         )
  45.       )
  46.   (setq pl5 (trans (setq p(polar pl3 (- ang (* 0.5 pi)) (* h))) 1 0))
  47.   (setq pl6 (trans (setq p (polar p ang w1)) 1 0))
  48.   (setq pl7 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
  49.   (setq pl8 (trans (setq p (polar p (+ pi ang) w1)) 1 0))
  50.   (entmake
  51.       (list
  52.         '(0 . "LWPOLYLINE")
  53.         '(100 . "AcDbEntity")
  54.         '(100 . "AcDbPolyline")
  55.         '(90 . 4)
  56.         '(70 . 1)
  57.         '(43 . 0.0)
  58.         '(38 . 0.0)
  59.         '(39 . 0.0)
  60.         (cons 10 (trans (setq p (polar pl7 (- ang (* 0.5 pi)) (* h))) 1 0))
  61.         (cons 10 (trans (setq p (polar p ang w2)) 1 0))
  62.         (cons 10 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
  63.         (cons 10 (trans (setq p (polar p (+ pi ang) w2)) 1 0))
  64.         )
  65.       )
  66.   (princ)
  67. )


如果你要的是这种效果:

本帖子中包含更多资源

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

x
 楼主| 发表于 2019-5-20 08:13 | 显示全部楼层
命令 ty 现在两个参考点
1.04
3.57
4.11
3.55


下面动画是我最终要的效果 不需要再二次调整就更好了


现在修改代码(satan421 提供修改的代码 其实也很好用)如下

(defun c:ty ()
(initget 7)
(setq p1 (getpoint "第一点:"))
(setq p2(getpoint p1 "\n**第二点:"))
(setq h (getdist "\n**输入宽度:"))
(setq w (getdist "\n**输入长度:"))
(setq w1 (getdist "\n**输入长度:"))
(setq w2 (getdist "\n**输入长度:"))

(setq ang (angle p1 p2) l (distance p1 p2))
(entmake
  (list
  '(0 . "LWPOLYLINE")
  '(100 . "AcDbEntity")
  '(100 . "AcDbPolyline")
  '(90 . 4)
  '(70 . 1)
  '(43 . 0.0)
  '(38 . 0.0)
  '(39 . 0.0)
  (cons 10 (trans (setq p (polar p1 (- ang (* 0.5 pi)) (* h))) 1 0))
  (cons 10 (trans (setq p (polar p ang w)) 1 0))
  (cons 10 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
  (cons 10 (trans (setq p (polar p (+ pi ang) w)) 1 0))
  )
)

(setq pl1 (trans (setq p(polar p1 (- ang (* 0.5 pi)) (* h))) 1 0))
(setq pl2 (trans (setq p (polar p ang w)) 1 0))
(setq pl3 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
(setq pl4 (trans (setq p (polar p (+ pi ang) w)) 1 0))
(entmake
  (list
  '(0 . "LWPOLYLINE")
  '(100 . "AcDbEntity")
  '(100 . "AcDbPolyline")
  '(90 . 4)
  '(70 . 1)
  '(43 . 0.0)
  '(38 . 0.0)
  '(39 . 0.0)
  (cons 10 (trans (setq p (polar pl3 (- ang (* 0.5 pi)) (* h))) 1 0))
  (cons 10 (trans (setq p (polar p ang w1)) 1 0))
  (cons 10 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
  (cons 10 (trans (setq p (polar p (+ pi ang) w1)) 1 0))
  )
  )
(setq pl5 (trans (setq p(polar pl3 (- ang (* 0.5 pi)) (* h))) 1 0))
(setq pl6 (trans (setq p (polar p ang w1)) 1 0))
(setq pl7 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
(setq pl8 (trans (setq p (polar p (+ pi ang) w1)) 1 0))
(entmake
  (list
  '(0 . "LWPOLYLINE")
  '(100 . "AcDbEntity")
  '(100 . "AcDbPolyline")
  '(90 . 4)
  '(70 . 1)
  '(43 . 0.0)
  '(38 . 0.0)
  '(39 . 0.0)
  (cons 10 (trans (setq p (polar pl7 (- ang (* 0.5 pi)) (* h))) 1 0))
  (cons 10 (trans (setq p (polar p ang w2)) 1 0))
  (cons 10 (trans (setq p (polar p (+ ang (* 0.5 pi)) h)) 1 0))
  (cons 10 (trans (setq p (polar p (+ pi ang) w2)) 1 0))
  )
  )
(princ)
)



本帖子中包含更多资源

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

x
发表于 2019-5-19 12:49 | 显示全部楼层
你看这个能不能解决你的问题
(defun c:ty ()
  (initget 7)
  (setvar "osmode" 0)
  (setq p1 (getpoint "第一点:"))          ;第一个矩形左下角点
  (setq p2  (getpoint p1 "\n**第二点:"))  ;控制矩形方向的控制点,也就是任何一个矩形的右下角点
  (setq h (getdist "\n**输入宽度:"))
   (setq w (getdist "\n**输入长度:"))
  (setq w1 (getdist "\n**输入长度:"))
  (setq w2 (getdist "\n**输入长度:"))
  (command "_ucs" "3" p1 p2 "")
  (command "_rectang" (list 0 0) (list w h))
  (command "_rectang" (list w 0) (list (+ w w1) h))
  (command "_rectang" (list (+ w w1) 0) (list (+ w w1 w2) h))
  (command "_ucs" "w")
  (setvar "osmode" 35)
)
发表于 2019-5-17 08:48 | 显示全部楼层
不太懂你的意思,但从你的描述来看,h、w、w1、w2应该依次输入0.92、4.28、2.39、4.28,应该就是你想要的效果了
 楼主| 发表于 2019-5-17 09:46 | 显示全部楼层
本帖最后由 youyou3810 于 2019-5-17 09:50 编辑

这是实际效果 高度不一样下图



我想要的效果下图


本帖子中包含更多资源

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

x
发表于 2019-5-17 13:38 | 显示全部楼层
youyou3810 发表于 2019-5-17 09:46
这是实际效果 高度不一样下图

那你就依次输入4.28、0.92、0.92、0.92
 楼主| 发表于 2019-5-17 15:06 | 显示全部楼层
satan421 发表于 2019-5-17 13:38
那你就依次输入4.28、0.92、0.92、0.92

4.28*0.92;2.39*0.92  4.28*0.92 是这样三个不同宽度矩形
 楼主| 发表于 2019-5-19 11:46 | 显示全部楼层
不错 是我想要的
 楼主| 发表于 2019-5-19 12:00 | 显示全部楼层
本帖最后由 youyou3810 于 2019-5-19 12:06 编辑

1.043.57
4.11
3.55

能直接去修改不需要移动点去端点吗

本帖子中包含更多资源

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

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

本版积分规则

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

GMT+8, 2024-5-19 14:39 , Processed in 0.189410 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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