I'm trying to mark my drawing before I programmatically insert a block so that I can programmatically undo the action if it only partially completes because of an error. Right now that insert method looks like this
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 is defined as
public static void MarkPosition()
{
doc.SendStringToExecute("MARKPOS ", true, false, true);
}
Finally, sending MARKPOS to the command line as i do above calls this method
[CommandMethod("MARKPOS")]
public void MarkPosition()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ed.Command("UNDO", "M");
}
The pointprompt somehow beats the MARKPOS call to the AutoCAD commandline so it tries to enter MARKPOS as the insertion point instead of pausing the C# method to wait for MARKPOS to execute as a command. How do I signal the program to wait and execute the MARKPOS command before prompting for the insertion point? I've tried Thread.sleep() after the SendStringToExecute call and that didn't work.