初级lisp代码问题
我正在尝试使用lisp生成函数。我想做两条偏移线,它们与中心线等距分布。所以我把这个函数命名为testpipe。
管径和管道长度由用户输入,线将通过极坐标计算创建。
但此功能可以加载到Autocad,但无法运行并显示“错误输入”
你能告诉我这个lisp文件有什么问题吗?
;pipe outerline function
(defun c:testpipe ()
;get user input
;get pipe diameter, and starting and ending point
(setq pd (getdist "\nPipe diameter:"))
(setq a (getdist "\nPipe distance:"))
;get insertion point
(setq ip (getpoint "\nInsertion point"))
;start polar calculation
(setq p2 (polar ip (dtr 90) (/ pd 2)))
(setq p3 (polar p2 (dtr 0) a))
(setq p4 (polar p3 (dtr 270) pd))
(setq p5 (polar p4 (dtr 180) a))
(setq p6 (polar p5 (dtr 90) (-(/ pd 2)))
;command
(command "line" ip p2 p3 p4 p5 p6 "c"
)
(princ)
;finish cleanly
) ;end of defun
;define function dtr
(defun dtr (x)
;define degrees to radians function
(* pi (/ x 180.0))
;divide the angle by 180 then
;multiply the result by the constant PI
) ;end of function
(princ) ;load cleanly (命令“_.PLINE”“\u non“p2”\u non“p3”\u non“p4”\u non“p5”\u C”“))
[编辑:它看起来很愚蠢,但我认为结尾“”是问题所在,但我错了…]
这是正确的:
(命令“_.PLINE”“\u non“p2”\u non“p3”\u non“p4”\u non“p5”\u C”)
对不起,M.R。 有几个建议我在我的库中使用d90 d180 d270,这些是转换为数字的DTR值,这样可以节省一些输入。
;in library
(setq d0 0.0) ; note dtr 0 is 0.0
(setq d90 (dtr 90.0))
(setq d180 (dtr 180.0))
(setq d270 (dtr 270.0))
; in code
(setq pt2 (polar pt1 d270 pd))
有很多不同的方法来解决这个问题。
这将从4个点创建一个4行矩形
(defun c:testpipe (/ pd a ip hd ha vl ll lr ur ul)
(initget 7)
(setq pd (getdist "\nPipe Diameter: "))
(initget 7)
(setq a (getdist "\nPipe Distance: "))
(initget 1)
(setq ip (getpoint "\nInsertion Point: "))
(setq hd (* pd 0.5)
ha (*a 0.5)
vl (distance '(0 0) (list ha hd))
ll (polar ip (angle '(0 0) (list (- ha) (- hd))) vl)
lr (polar ip (angle '(0 0) (list (+ ha) (- hd))) vl)
ur (polar ip (angle '(0 0) (list (+ ha) (+ hd))) vl)
ul (polar ip (angle '(0 0) (list (- ha) (+ hd))) vl))
(command "_.LINE" ll lr ur ul "_CL")
(prin1))
查看(initget)。它可以防止您输入错误的值
再看看
论坛中发布的标签。
玩得开心-大卫 谢谢大家
我会比较你和我的密码,这样我就可以自己学习了。
顺便问一下,有什么好的材料或网站来学习lisp吗? http://www.afralisp.net/index.php
页:
[1]