【发布时间】:2015-04-29 20:53:56
【问题描述】:
我正在尝试在以编程方式插入块之前标记我的绘图,以便如果由于错误而仅部分完成,我可以以编程方式撤消该操作。现在插入方法看起来像这样
public void askForInsertionPoint
{
StateManagementExtensions.MarkPosition();
try
{
PromptPointResult pr = ed.GetPoint("\nSelect insertion point: ");
Point3d insPt = pr.Value;
}
catch(Exception e)
{
//TODO handle exception with undo
}
}
MarkPosition 定义为
public static void MarkPosition()
{
doc.SendStringToExecute("MARKPOS ", true, false, true);
}
最后,像我上面那样将 MARKPOS 发送到命令行调用这个方法
[CommandMethod("MARKPOS")]
public void MarkPosition()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ed.Command("UNDO", "M");
}
pointprompt 以某种方式击败了对 AutoCAD 命令行的 MARKPOS 调用,因此它尝试输入 MARKPOS 作为插入点,而不是暂停 C# 方法以等待 MARKPOS 作为命令执行。在提示插入点之前,如何向程序发出等待并执行 MARKPOS 命令的信号?我在 SendStringToExecute 调用之后尝试了 Thread.sleep(),但没有成功。
【问题讨论】:
-
你为什么不直接打电话给
MarkPosition呢? (或者可能是ed.Command("UNDO", "M");?) -
因为这样做会由于某种原因引发 eInvalidInput 异常
-
我现在主要使用 RealDWG,但是您可以使用 Transaction 来代替设置撤消标记吗?
标签: c# autocad autocad-plugin