- 积分
- 2124
- 明经币
- 个
- 注册时间
- 2011-4-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 mrhvslisp 于 2011-10-18 10:39 编辑
- /*代码来自CAD.net开发人员手册,
本例提示用户输入五个点,然后根据输入的点创建多段线。该多段线是闭合的,所形成的面积显示在消息框中。因为多段线不需要添加到块中,所以在命令结束前需要删除它。问题在代码第51行*/
- using Autodesk.AutoCAD.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
- }
- }
|
|