Autocad右键单击事件处理程序
本文关键字:程序 事件处理 单击 右键 Autocad | 更新日期: 2023-09-27 18:26:38
我写了这样的代码:
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,我想右键单击或空格键单击以关闭循环。我能做这个吗?
它在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
,通过更改循环评估,当用户选择"是"时,你就会出现,你可以设置为空格键。
希望这有帮助:)