669423907 发表于 2013-8-7 21:37:37

求助关于U型孔角度问题

我把角度改成用鼠标左右键选取的时候,左键的就没问题,右键的角度就不对了,不知道是哪里出错了?
把 (setq j (getangle "\n 输入旋转角度:"))和
(setq pt (getpoint "\n左键0°,右键90°"))
(if pt (setq j 0) (setq j 90))
都去掉之后,可以用鼠标动态控制角度,但中心线又出不来,要怎么改呢?
诚望指点

(defun c:q1(/ os a b d ang p1 aa p2 p3 bb p4 p5 p6 pp qq)
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(setq b (getdist "\n请输入腰孔的宽度:"))
(setq a (getdist "\n请输入腰孔的长度:"))
(setq k (* 0.05 a));中心线伸出长度
(setq d (- a b))

;(setq j (getangle "\n 输入旋转角度:"))

(setq pt (getpoint "\n左键0°,右键90°"))
(if pt (setq j 0) (setq j 90))

(setq p1 (getpoint "\n请指定腰孔的中心点:"))
(setq aa (/ d 2.0) p2 (polar p1 0 aa) p3 (polar p1 pi aa) bb (/ b 2.0))
(setq p4 (polar p3 (* pi 1.5) bb) p5 (polar p2 (* pi 1.5) bb) p6 (polar p3 (* pi 0.5) bb))
(command "layer" "m" 0 "l" "continuous" 0 "c" 7 0"")
 (command "ltscale" 5);设置线型比例
(command "pline" p4 "w" "0" "0" p5 "a" "ce" p2 "a" "180" "l" p6 "a" "ce" p3 "a" "180" "l" "")
(command "rotate" "l" "" p1 (* (/ 180 pi) j))

(command "layer" "m" 5 "l" "center" 5 "c" 1 5 "")
 (command "ltscale" 5);设置线型比例
(command "line" (polar p3 (- pi) (+ (* b 0.5) k)) (polar p2 (* pi 0) (+ (* b 0.5) k)) "")
(command "rotate" "l" "" p1 (* (/ 180 pi) j))
(command "line" (polar p3 (+ (* pi 0.5)) (+ (* b 0.5) k)) (polar p3 (* pi 1.5) (+ (* b 0.5) k)) "")
(command "rotate" "l" "" p1 (* (/ 180 pi) j))
(command "line" (polar p2 (+ (* pi 0.5)) (+ (* b 0.5) k)) (polar p2 (* pi 1.5) (+ (* b 0.5) k)) "")
(command "rotate" "l" "" p1 (* (/ 180 pi) j))
(setvar "osmode" os)
(princ))

Andyhon 发表于 2013-8-7 22:24:23

Command: (* (/ 180 pi) j)
5156.62

Command: (* (/ pi 180) j)
1.5708

不过建议 J ==> (* Pi0.5)

669423907 发表于 2013-8-8 11:07:06

Andyhon 发表于 2013-8-7 22:24 static/image/common/back.gif
Command: (* (/ 180 pi) j)
5156.62



Andyhon长老,谢谢您的关注。请问这两个是什么意思呢?
Command: (* (/ 180 pi) j)
5156.62

Command: (* (/ pi 180) j)
1.5708


J ==> (* Pi0.5)是指(setq j (* Pi0.5))吗?

Andyhon 发表于 2013-8-8 11:28:47

(command "rotate" ...)
此处角度 0-360

(if pt (setq j 0) (setq j 90))
J 值别换算了...
---------------------------------------------
但建议直接依条件换算出点位绘制
不建议绘制后多一道 旋转

669423907 发表于 2013-8-8 17:33:12

Andyhon 发表于 2013-8-8 11:28 static/image/common/back.gif
(command "rotate" ...)
此处角度 0-360



谢谢Andyhon长老,这样改行了,只是有时候,当窗口缩得很小时,中心线不会超出U型孔。
不知Andyhon长老方不方便帮添加记忆功能呢,
当不输入宽和长的时候,自动为上一次的值,谢谢您了

(defun c:uk()
(command "undo" "be")

;(setq os (getvar "osmode"))
;(setvar "osmode" 0)

(setq b (getdist "\n请指定U型孔的宽度:"))
(setq a (getdist "\n请指定U型孔的长度:"))
(setq k (* 0.05 a));中心线伸出长度
(setq d (- a b))

(setq dj (getpoint "\n左键0°,右键90°"))
(if dj (setq j 0)(setq j (* pi 0.5)))

(setq p1 (getpoint "\n请指定U型孔的中心点:"))
(setq aa (/ d 2.0) p2 (polar p1 0 aa) p3 (polar p1 pi aa) bb (/ b 2.0))
(setq p4 (polar p3 (* pi 1.5) bb) p5 (polar p2 (* pi 1.5) bb) p6 (polar p3 (* pi 0.5) bb))

(command "pline" p4 "w" "0" "0" p5 "a" "ce" p2 "a" "180" "l" p6 "a" "ce" p3 "a" "180" "l" "")
(command "rotate" "l" "" p1 (* (/ 180 pi) j))
(command "chprop" (entlast) "" "p" "la" (getvar "clayer") "ltscale" (* 0.5 b) "")

(setq la (getvar"clayer"))
(command "layer" "m" "3中心线" "c" "1" "" "lw" "0.13" "" "lt" "CENTER" "" "" "clayer" la)

(command "line" (polar p3 (- pi) (+ (* b 0.5) k)) (polar p2 (* pi 0) (+ (* b 0.5) k)) "")
(command "rotate" "l" "" p1 (* (/ 180 pi) j))
(command "chprop" (entlast) "" "p" "la" "3中心线" "ltscale" (* 0.5 b) "")

(command "line" (polar p3 (+ (* pi 0.5)) (+ (* b 0.5) k)) (polar p3 (* pi 1.5) (+ (* b 0.5) k)) "")
(command "rotate" "l" "" p1 (* (/ 180 pi) j))
(command "chprop" (entlast) "" "p" "la" "3中心线" "ltscale" (* 0.5 b) "")

(command "line" (polar p2 (+ (* pi 0.5)) (+ (* b 0.5) k)) (polar p2 (* pi 1.5) (+ (* b 0.5) k)) "")
(command "rotate" "l" "" p1 (* (/ 180 pi) j))
(command "chprop" (entlast) "" "p" "la" "3中心线" "ltscale" (* 0.5 b) "")

(command "undo" "e")

;(setvar "osmode" os)
(princ))

Andyhon 发表于 2013-8-8 17:57:37

函数 坛子里有...

引用例
http://bbs.mjtd.com/thread-45891-1-1.html
6#

(setvar "osmode" 0)
关了有副作用底...

669423907 发表于 2013-8-9 11:46:34

Andyhon 发表于 2013-8-8 17:57 static/image/common/back.gif
函数 坛子里有...

引用例


调一下位置,就可以了
(setq p1 (getpoint "\n请指定U型孔的中心点:"))

(setq os (getvar "osmode"))
(setvar "osmode" 0)

zrlmj 发表于 2023-7-6 13:10:10

669423907 发表于 2013-8-9 11:46
调一下位置,就可以了
(setq p1 (getpoint "\n请指定U型孔的中心点:"))



谢谢楼主!带记忆功能实现了吗
页: [1]
查看完整版本: 求助关于U型孔角度问题