By Adam Nagy
I'm using WriteMessage() in a longer command and would like to keep the user updated by writing messages to the command window. Unfortunately, when I use WriteMessage(), its content only appears once my command finished. How could I update/refresh the Command Window to show the text I wrote?
Solution
If you add a carriage return (C# \n, VB.NET vbCr/vbCrLf) to the end of your text then it will appear straight away. As mentioned in the comments section, VB.NET vbCr might not work as well as vbCrLf does.
[CommandMethod("AEN1WriteInfo")]
static public void AEN1WriteInfo()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.
DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("Something\n");
for (int i = 0; i < 3; i++)
{
System.Threading.Thread.Sleep(1000);
// carriage return at the end
ed.WriteMessage(i.ToString() + "\n");
}
}