先看一下完成效果(本文章根据《AutoLISP&DCL基础篇》进行编辑和解读)
(defun c:colorcircle();定义一个画带有颜色圆的命令
(setq cenpt(getpoint "input the center point of the circle"));在屏幕中点取圆心的位置
(setq radius(getreal "input the radius"));输入圆的半径
(setq color(getint "input the number of color"))
(if (> radius 0)
(progn;如果半径大于0,则执行下面两个命令,即画圆、上色
(command "circle" cenpt radius)
(command "chprop" (entlast) "" "c" color "")
);我们在CAD中输入chprop后执行的动作有如下:选取-空格(确定)-c(改变图层颜色特性)-输入颜色索引(这一步骤在我的CAD中是让我选择真彩色什么的,有一点没有搞懂,我也是个变成小白哈哈哈),这些步骤对应上面的命令。
(progn
(alert "the radius is wrong");如果半径<=0,则弹出弹窗警告。
)
)
)