- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I cannot get the AutoCAD display to get updated during the execution of a command.
There are two cases for which i like the display to get updated:
1. When changing the current layer, the ribbon must show the new current while the command is executed.
See the sample below. The command may be called from Palette or WPF controll.
2. After changing the Document Display Size but before taking a snapshot.
I've tried different update calls, document and session context, windows messages etc. but the display always gets updated after the command is finished.
I've found one sollution and that's issue an other command using SendStringToExecute but this result in an other issue, synchronisation.
The update problem occurs in all versions of AutoCAD up to 2017.
Any other suggestions or is this simply not possible.
Thanks in advance for any help.
using System;
using System.Threading;
using System.Reflection;
using System.Drawing;
using System.Windows.Forms;
using frmApp = System.Windows.Forms.Application;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof(TestAcadUpdate.Class1))]
namespace TestAcadUpdate
{
public class Class1
{
/// <summary>
/// Update Ribbon to display the new Current Layer BEFORE the end of this command,
/// without a user interaction (ed.GetXXX),
/// and (if possible) without Session mode
/// </summary>
[CommandMethod("TestUCLD", CommandFlags.Session )]
public static void UpdateCurrentLayerDisplay()
{
Document doc = null;
Editor ed = null;
Database db = null;
try
{
doc = AcadApp.DocumentManager.MdiActiveDocument;
ed = doc.Editor;
db = doc.Database;
//LockDocument because of Session Mode
var docLck = default(DocumentLock);
using (docLck = doc.LockDocument())
{
var tr = default(Transaction);
using (tr = db.TransactionManager.StartTransaction())
{
//Change CurrentLayer to "0"
db.Clayer = db.LayerZero;
//var lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
var layer0 = (LayerTableRecord)tr.GetObject(db.LayerZero, OpenMode.ForWrite);
//Force a graphics update
layer0.IsOff = layer0.IsOff;
ed.ApplyCurDwgLayerTableChanges();
tr.Commit();
}
doc.TransactionManager.EnableGraphicsFlush(true);
doc.TransactionManager.QueueForGraphicsFlush();
}
//I'll like the Ribbon to display the new CurrentLayer NOW
ed.UpdateScreen();
ed.Regen();
AcadApp.UpdateScreen();
Autodesk.AutoCAD.Internal.Utils.FlushGraphics();
//This doesn't work either, and is not what i'll want
//string esc = null;
//esc += '\x03';
//doc.SendStringToExecute(esc, true, false, false);
//PromptPointResult ppr = ed.GetPoint("\n Give me a Point: ");
//if (ppr.Status != PromptStatus.OK)
// return;
var cp = Cursor.Position;
Cursor.Position = new Point(cp.X, cp.Y);
frmApp.DoEvents();
//Simulate other drawing and calculation activities
for (int i = 0; i < 10; i++)
Thread.Sleep(1000);
}
catch (System.Exception ex)
{
if (ed != null)
ed.WriteMessage("\n Error {0}: {1} " , MethodBase.GetCurrentMethod().Name, ex.Message);
else
MessageBox.Show(ex.Message, MethodBase.GetCurrentMethod().Name, MessageBoxButtons.OK);
}
}
}
}
Solved! Go to Solution.