乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 37|回复: 2

PromptPointOptions 类的疑惑,问题在代码第51行

[复制链接]

24

主题

42

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
138
发表于 2011-10-18 10:29:00 | 显示全部楼层 |阅读模式
using Autodesk..ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
[CommandMethod("CalculateDefinedArea")]
public static void CalculateDefinedArea()
{
  // 提示用户输入 5 个点    Prompt the user for 5 points
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
  PromptPointResult pPtRes;
  Point2dCollection colPt = new Point2dCollection();
  PromptPointOptions pPtOpts = new PromptPointOptions("");
  // 提示输入第一个点   Prompt for the first point
  pPtOpts.Message = "\nSpecify first point: ";
  pPtRes = acDoc.Editor.GetPoint(pPtOpts);
  colPt.Add(new Point2d(pPtRes.Value.X, pPtRes.Value.Y));
  // 如果用户按了 ESC 键或取消了命令就退出   Exit if the user presses ESC or cancels the command
  if (pPtRes.Status == PromptStatus.Cancel) return;
  int nCounter = 1;
  while (nCounter <= 4)
  {
      // 提示指定下一个点   Prompt for the next points
      switch(nCounter)
      {
          case 1:
              pPtOpts.Message = "\nSpecify second point: ";
              break;
          case 2:
              pPtOpts.Message = "\nSpecify third point: ";
              break;
          case 3:
              pPtOpts.Message = "\nSpecify fourth point: ";
              break;
          case 4:
              pPtOpts.Message = "\nSpecify fifth point: ";
              break;
      }
      // 使用前一个点作为基点   Use the previous point as the base point
      pPtOpts.UseBasePoint = true;
      pPtOpts.BasePoint = pPtRes.Value;
     //问题在这里,UseBasePoint 和BasePoint 属性指的是什么?请指教。
      pPtRes = acDoc.Editor.GetPoint(pPtOpts);
      colPt.Add(new Point2d(pPtRes.Value.X, pPtRes.Value.Y));
      if (pPtRes.Status == PromptStatus.Cancel) return;
      // 递增计数器    Increment the counter
      nCounter = nCounter + 1;
  }
  // 用5个点创建多段线   Create a polyline with 5 points
  using (Polyline acPoly = new Polyline())
  {
      acPoly.AddVertexAt(0, colPt[0], 0, 0, 0);
      acPoly.AddVertexAt(1, colPt[1], 0, 0, 0);
      acPoly.AddVertexAt(2, colPt[2], 0, 0, 0);
      acPoly.AddVertexAt(3, colPt[3], 0, 0, 0);
      acPoly.AddVertexAt(4, colPt[4], 0, 0, 0);
      // 闭合多段线   Close the polyline
      acPoly.Closed = true;
      // 查询多段线的面积   Query the area of the polyline
      Application.ShowAlertDialog("Area of polyline: " +
                                  acPoly.Area.ToString());
      // 销毁多段线   Dispose of the polyline
  }
}
[/ol]
  1. /*代码来自CAD.net开发人员手册,
  2. 本例提示用户输入五个点,然后根据输入的点创建多段线。该多段线是闭合的,所形成的面积显示在消息框中。因为多段线不需要添加到块中,所以在命令结束前需要删除它。问题在代码第51行*/
  3. using Autodesk..ApplicationServices;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using Autodesk.AutoCAD.Runtime;
  8. [CommandMethod("CalculateDefinedArea")]
  9. public static void CalculateDefinedArea()
  10. {
  11.   // 提示用户输入 5 个点    Prompt the user for 5 points
  12.   Document acDoc = Application.DocumentManager.MdiActiveDocument;
  13.   PromptPointResult pPtRes;
  14.   Point2dCollection colPt = new Point2dCollection();
  15.   PromptPointOptions pPtOpts = new PromptPointOptions("");
  16.   // 提示输入第一个点   Prompt for the first point
  17.   pPtOpts.Message = "\nSpecify first point: ";
  18.   pPtRes = acDoc.Editor.GetPoint(pPtOpts);
  19.   colPt.Add(new Point2d(pPtRes.Value.X, pPtRes.Value.Y));
  20.   // 如果用户按了 ESC 键或取消了命令就退出   Exit if the user presses ESC or cancels the command
  21.   if (pPtRes.Status == PromptStatus.Cancel) return;
  22.   int nCounter = 1;
  23.   while (nCounter <= 4)
  24.   {
  25.       // 提示指定下一个点   Prompt for the next points
  26.       switch(nCounter)
  27.       {
  28.           case 1:
  29.               pPtOpts.Message = "\nSpecify second point: ";
  30.               break;
  31.           case 2:
  32.               pPtOpts.Message = "\nSpecify third point: ";
  33.               break;
  34.           case 3:
  35.               pPtOpts.Message = "\nSpecify fourth point: ";
  36.               break;
  37.           case 4:
  38.               pPtOpts.Message = "\nSpecify fifth point: ";
  39.               break;
  40.       }
  41.       // 使用前一个点作为基点   Use the previous point as the base point
  42.       pPtOpts.UseBasePoint = true;
  43.       pPtOpts.BasePoint = pPtRes.Value;
  44.      //问题在这里,UseBasePoint 和BasePoint 属性指的是什么?请指教。
  45.       pPtRes = acDoc.Editor.GetPoint(pPtOpts);
  46.       colPt.Add(new Point2d(pPtRes.Value.X, pPtRes.Value.Y));
  47.       if (pPtRes.Status == PromptStatus.Cancel) return;
  48.       // 递增计数器    Increment the counter
  49.       nCounter = nCounter + 1;
  50.   }
  51.   // 用5个点创建多段线   Create a polyline with 5 points
  52.   using (Polyline acPoly = new Polyline())
  53.   {
  54.       acPoly.AddVertexAt(0, colPt[0], 0, 0, 0);
  55.       acPoly.AddVertexAt(1, colPt[1], 0, 0, 0);
  56.       acPoly.AddVertexAt(2, colPt[2], 0, 0, 0);
  57.       acPoly.AddVertexAt(3, colPt[3], 0, 0, 0);
  58.       acPoly.AddVertexAt(4, colPt[4], 0, 0, 0);
  59.       // 闭合多段线   Close the polyline
  60.       acPoly.Closed = true;
  61.       // 查询多段线的面积   Query the area of the polyline
  62.       Application.ShowAlertDialog("Area of polyline: " +
  63.                                   acPoly.Area.ToString());
  64.       // 销毁多段线   Dispose of the polyline
  65.   }
  66. }

回复

使用道具 举报

0

主题

23

帖子

2

银币

初来乍到

Rank: 1

铜币
23
发表于 2011-10-18 15:49:00 | 显示全部楼层
楼主把49行以为
pPtOpts.UseBasePoint = false;
再运行一下就能看差别了,以一点为基点,到鼠标点取下一点之前会有从基点到光标处的一条直线,有点儿像拖拽的效果!
回复

使用道具 举报

2

主题

19

帖子

2

银币

初来乍到

Rank: 1

铜币
27
发表于 2012-6-25 10:02:00 | 显示全部楼层
飘过学习了~
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-6-29 19:07 , Processed in 0.541492 second(s), 59 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表