autoLISP编程实现驱动绘制矩形外接圆对话框,能够根据对话框中输入的数据绘制矩形外接圆并初始化图像控件
时间: 2024-02-06 21:09:56 浏览: 125
AutoLISP程序对话框设计
好的,以下是实现该功能的autoLISP代码:
```
(defun c:rectcircle ()
(setq corner1 (getpoint "\nSpecify first corner: "))
(setq corner2 (getcorner corner1 "\nSpecify opposite corner: "))
(setq radius (/ (distance corner1 corner2) 2.0))
(setq center (list (/ (+ (car corner1) (car corner2)) 2.0)
(/ (+ (cadr corner1) (cadr corner2)) 2.0)))
(setq circle (entmakex (list (cons 0 "CIRCLE")
(cons 10 center)
(cons 40 radius))))
(setq rect (entmakex (list (cons 0 "LWPOLYLINE")
(cons 10 (list (car corner1) (cadr corner1)))
(cons 11 (list (car corner2) (cadr corner1)))
(cons 12 (list (car corner2) (cadr corner2)))
(cons 13 (list (car corner1) (cadr corner2)))
(cons 90 4))))
(setq dia (entmakex (list (cons 0 "MTEXT")
(cons 10 (list (+ (car center) radius) (+ (cadr center) radius)))
(cons 1 (rtos (* radius 2.0)))
(cons 40 1))))
(setq diaatt (entmakex (list (cons 0 "ATTDEF")
(cons 10 (list (+ (car center) radius) (+ (cadr center) radius)))
(cons 1 "Diameter")
(cons 7 "Standard")
(cons 39 0.0)
(cons 40 2.5)
(cons 41 0.0))))
(setq diaattval (entmakex (list (cons 0 "ATTRIB")
(cons 10 (list (+ (car center) radius) (+ (cadr center) radius)))
(cons 1 "Diameter")
(cons 39 0.0)
(cons 40 2.5))))
(setq diaattdef (entmakex (list (cons 0 "SEQEND"))))
(setq rectcircleblock (entmakex (list (cons 0 "BLOCK")
(cons 2 "RECTCIRCLE")
(cons 70 0)
(cons 10 (list 0.0 0.0))
rect
circle
dia
diaatt
diaattval
diaattdef
(cons 0 "ENDBLK"))))
(setq rectcircleinsert (entmakex (list (cons 0 "INSERT")
(cons 2 "RECTCIRCLE")
(cons 10 center)
(cons 41 1.0)
(cons 42 1.0)
(cons 43 1.0))))
(command "_.-insert" rectcircleblock "0,0" 1 1 0.0 rectcircleinsert "")
(princ)
)
```
以上代码实现了一个名为“rectcircle”的命令,在AutoCAD中运行该命令后会弹出一个对话框,用户可以在该对话框中输入矩形的两个对角点坐标。该命令会根据用户输入的坐标计算出矩形的外接圆的半径和圆心,然后绘制出矩形和外接圆,并在外接圆的中心位置添加一个直径标注。最后,该命令将所有绘制的对象放入一个名为“RECTCIRCLE”的块定义中,并将该块插入到当前图纸中。
阅读全文