CAD lisp程序注释解析

CAD lisp程序注释解析,第1张

(defun c:try( / p)定义命令行命令“try”,定义局部变量“p”

(setq p (getpoint "from point: "))利用交互获得一个点,将该点坐标存入变量“p”当中

(command "PLINE")利用命令行启动“PLINE”多段线命令,

(while p循环开始,当p不为空(即交互时一直给出下一点)时,无限循环。

(command p)将p的值(用户给出或选定的坐标点)输入至命令行,做为“PLINE”命令的参数。

(setq p (getpoint "to point: "))获取下一点坐标,重新存入变量p中

)

(command)等同于按下空格或回车键,用于结束“PLINE”命令

)

(princ "\n加载成功!启动快捷键 ccc")

加载Active X功能

(vl-load-com)

定义模型空间指针

(setq Mspace

(vla-get-ModelSpace

(vla-get-ActiveDocument (vlax-get-acad-object))

)

)

度->弧度函数

(defun DetoRad (numberOfDegrees)

(* pi (/ numberOfDegrees 180.0))

)

主程序

(defun c:ccc (/ pt1 pt2 len deg deg1 deg2 key)

获取基点,第二个角点(或边长,角度,设置默认值)

(setq pt1 (getpoint "\n点取或输入一个角点:"))

(initget "b B")

(setq pt2 (getpoint pt1 "\n点取或输入第二个角点或指定边长(b):")

)

(if (= pt2 "B")

(progn

(setq len (getdist "\n点取或输入边长(默认为1000):"))

(if (not len)

(setq len 1000)

)

)

)

(if len

(setq deg (getint "\n输入图形与水平轴的夹角(默认为0):"))

)

(if (not deg)

(setq deg 0)

)

(if (and pt2 (/= pt2 "B"))

(setq len (distance pt1 pt2)

deg (angle pt1 pt2)

)

)

获取绘图方向,逆时针/顺时针

(initget "+ -")

(setq

key (getpoint

"\n选取方向参考点或输入“+”(逆时针),“-”(顺时针)(默认逆时针):"

)

)

(if (and key (and (/= key "+") (/= key "-")))

(progn

(setq deg1 (angle pt1 key )

deg2 (angle pt1 pt2)

deg1 (- deg1 deg2)

)

(cond ((<= deg1 pi) (setq key "+"))

((>deg1 pi) (setq key "-"))

)

)

)

(if (not key) (setq key "+"))

(draw pt1 len deg key)

(princ)

)

画线子程序

(defun DRAW (pt1 len deg key / rr deg2 ptn num)

计算半径,首次偏移距离

(setq rr (/ len (+ 8 (* (sqrt 3) 2)))

l1 (* (/ RR (sqrt 3)) 2)

pt pt1

num 5

)

(cond ((= key "+") (setq deg2 (+ deg (DetoRad 60))))

((= key "-") (setq deg2 (- deg (DetoRad 60))))

)

(command "PLINE")

画三角形

(repeat 3

(progn

(command pt)

(setq pt (polar pt deg len))

(cond ((= key "+")(setq deg (+ deg (DetoRad 120)) ))

((= key "-")(setq deg (- deg (DetoRad 120)) ))

)

)

)

(command "c")

画圆形

(setq pt1 (polar (polar pt1 deg l1) deg2 l1))

(repeat 5

(progn

(setq pt pt1)

(repeat num

(progn

(vla-addcircle Mspace (vlax-3d-point pt) rr)

(setq pt (polar pt deg2 (* rr 2)))

)

)

(setq pt1 (polar pt1 deg (* rr 2))

num (1- num))

)

)

)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11895683.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存