CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2025 开发者帮助

创建矩形

2024-5-18 19:14| 发布者: admin| 查看: 113| 评论: 0|原作者: admin|来自: AutoCAD

创建矩形

创建矩形

此 AutoCAD JavaScript 教程演示了如何提示用户输入点并将值传递给 AutoCAD 命令。

在本教程中,您将:

  • 提示用户输入一个点,如果成功,则提示输入第二个点

  • 使用 AutoCAD RECTANG 命令根据指定的点绘制矩形多段线

    1. 在纯文本文件中键入以下 JavaScript 语句。

      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);
      }
    2. 将文件另存为 getPoint.js

    3. 将要加载 JavaScript 文件的路径添加到 TRUSTEDPATHS 系统变量的现有路径。

    4. 在 AutoCAD 命令提示符下,输入 webload,然后再次按 Enter 键以使用“加载”选项。

    5. 在提示符下,输入 getPoint.js 文件的 URI。Enter javascript URL to load:

      如果在 TRUSTEDPATHS 系统变量中列出的路径之一中找到该文件,则该文件将加载到 AutoCAD 中并由 AutoCAD 执行。getPoint.js

    6. 指定第一个点和第二个点以创建矩形折线。

      使用 JavaScript 图像创建矩形


路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2025-3-5 15:50

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部