PromptPointOptions 类的疑惑,问题在代码第51行
本帖最后由 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;
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);
acPoly.AddVertexAt(1, colPt, 0, 0, 0);
acPoly.AddVertexAt(2, colPt, 0, 0, 0);
acPoly.AddVertexAt(3, colPt, 0, 0, 0);
acPoly.AddVertexAt(4, colPt, 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
}
}
楼主把49行以为
pPtOpts.UseBasePoint = false;
再运行一下就能看差别了,以一点为基点,到鼠标点取下一点之前会有从基点到光标处的一条直线,有点儿像拖拽的效果! 飘过学习了~
页:
[1]