Autocad右键单击事件处理程序

时间:2013-08-05 15:17:18

标签: c# .net autocad autodesk autocad-plugin

我写了这段代码:

int count = 1;

while (true)
{

    pointOptions.Message = "\nEnter the end point of the line: ";
    pointOptions.UseBasePoint = true;
    pointOptions.BasePoint = drawnLine.EndPoint;
    pointResult = editor.GetPoint(pointOptions);

    if (pointResult.Status == PromptStatus.Cancel)
    {
        break;
    }

    if (count == 1)
    {
        drawnLine.AddVertexAt(count, pointResult.Value.Convert2d(new Plane()), 0, 0, 0);
        blockTableRecord.AppendEntity(drawnLine);
        transaction.AddNewlyCreatedDBObject(drawnLine, true);
    }
    else
    {
        stretch(drawnLine, pointResult.Value, Point3d.Origin);
    }

    editor.Regen();

    count++;
}

代码工作正常,但为了完成绘图我必须键入ESC,我想右键单击或空格键单击以关闭我的循环。我可以这样做吗?

1 个答案:

答案 0 :(得分:1)

它在PromptPointOptions中见下面的代码示例:

// Set promptOptions
var pointOptions = new PromptPointOptions("\nSelect Next Point: ");
pointOptions.SetMessageAndKeywords("\nSelect Next Point: or Exit [Y]","Yes");
pointOptions.AppendKeywordsToMessage = true;
pointOptions.AllowArbitraryInput = true;
pointOptions.UseBasePoint = true;
pointOptions.BasePoint = drawnLine.EndPoint;

// While user wants to draw the polyline
while (pointResult.Status != PromptStatus.Keyword)
{
// Get point
pointResult = Editor.GetPoint(pointOptions);

// stop creating polyline
if (pointResult.Status == PromptStatus.Cancel)
    break;

if (count == 1) {

    // Get base point and add to the modelspace
    drawnLine.AddVertexAt(count, pointResult.Value.Convert2d(new Plane()), 0, 0, 0);
    blockTableRecord.AppendEntity(drawnLine);
    transaction.AddNewlyCreatedDBObject(drawnLine, true);
} else

    // Grow the polyline
    stretch(drawnLine, pointResult.Value, Point3d.Origin);

// Regen
editor.Regen();

count++;
}

你要找的是PromptPointOptions.SetMessageAndKeywords并且通过改变你的循环评估,你会在用户选择是时出来,你可以设置为空格键。

希望这会有所帮助:)