var firstPoint, secondPoint;
// Prompt for the user for the first point
var options = new Acad.PromptPointOptions("Specify the first point of the rectangle: ");
Acad.Editor.getPoint(options).then(onFirstPoint,error);
// If the first point was successful, prompt the user for a second point
function onFirstPoint(arg)
{
var obj = arg;
firstPoint = obj.value;
// Prompt for the user for the second point
var options = new Acad.PromptPointOptions("Specify the opposite corner of the rectangle: ");
Acad.Editor.getPoint(options).then(onSecondPoint,error);
}
// If an error occurred, display a general error message
function error()
{
alert("Invalid point specified.");
}
// If both points were successfully specified, then draw the rectangle
function onSecondPoint(arg)
{
var obj = arg;
secondPoint = obj.value;
// Draw the rectangle
Acad.Editor.executeCommand("RECTANG", firstPoint.x + "," + firstPoint.y, "", secondPoint.x + "," + secondPoint.y);
}
将文件另存为 getPoint.js。
将要加载 JavaScript 文件的路径添加到 TRUSTEDPATHS 系统变量的现有路径。
在 AutoCAD 命令提示符下,输入 webload,然后再次按 Enter 键以使用“加载”选项。
在提示符下,输入 getPoint.js 文件的 URI。Enter javascript URL to load: