.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Redrawing the screen during execution of a Command Method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I would like to be able to have the screen refresh periodically to show the new objects I have added as a command method proceeds to execute. I am hoping to be able to achieve a kind of simple animation by doing this, and also to show progress while a computationally intensive operation is under way. Is there a way that I can do this?
I have tried using AcadApp.DocumentManager.MdiActiveDocument..E
Thanks!
Solved! Go to Solution.
Re : Redrawing the screen during execution of a Command Method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
Look at the TransactionManager.QueueForGraphicsFlush() method.
.
Re : Redrawing the screen during execution of a Command Method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I tried calling TransactionManager.Database.QueueForGraphicsFlush(
Is there perhaps some other command to tell the system to process events? Transients seem to do this. But I don't really want to draw transients. I just want actual entities to appear as a command progresses.
Thanks!
Re : Redrawing the screen during execution of a Command Method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
What I even notice with the Transient object is that if the command is busy doing something, even calling TransientManager.CurrentTransientManager.U
Any idea are appreciated!
Re : Redrawing the screen during execution of a Command Method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Perhaps I misunderstand what you want to do but this is working for me:
[CommandMethod("Test")]
public void Test()
{
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptResult pr = ed.GetString("\nEnter a string: ");
if (pr.Status != PromptStatus.OK)
return;
string str = pr.StringResult;
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
PromptPointOptions options = new PromptPointOptions("\nInsertion point: ");
options.AllowNone = true;
PromptPointResult ppr;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord space =
(BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
while (true)
{
ppr = ed.GetPoint(options);
if (ppr.Status != PromptStatus.OK)
break;
DBText text = new DBText();
text.TextString = str;
text.Position = ppr.Value.TransformBy(ucs);
space.AppendEntity(text);
tr.AddNewlyCreatedDBObject(text, true);
db.TransactionManager.QueueForGraphicsFlush();
}
tr.Commit();
}
}
Re : Redrawing the screen during execution of a Command Method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Yes I understand. I believe that works for you because in each pass through your loop you pause for user input. Pausing for user input returns control to Autocad so the user can specify the next point. At that moment it is possible for Autocad to refresh the screen. But imagine if you were not pausing for user input, but were instead computing the next point via some mathematical procedure. What you would see is that all your lines appear at once. This doesn't happen simply because the lines are being drawn really fast; it happens because Autocad does not have the opportunity to redraw the screen. So, let's say you were drawing 100 lines in your command and the procedure was complex enough that it took 1/10 of a second to figure out the end points of each line. You would observe that Autocad freezes for about 10 seconds and then all 100 lines would appear at once instead of sequentially.
The only method I've seen for truly drawing things dynamically is using Transients as shown here. Perhaps that's the only way to do it. In this method control does return to Autocad (the command method exits), but the Transient continues to run in the background by means of Windows Messages being fired.
Re : Redrawing the screen during execution of a Command Method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Gile.
The reason your code works is because it acquires user input in the loop, which causes AutoCAD to update the display.
In fact, there is an undocumented method in Autodesk.AutoCAD.Internal.Utils that seems to be precisely for that purpose, called FlushGraphics(), and all it does is call acutPrompt().
Re : Redrawing the screen during execution of a Command Method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
You can post some code snippets showing more precisely what it is you've tried that isn't working.
You need to use the TransactionManager of the Document object, not the TransactionManager of the Database, and you need to commit the transaction in order for AutoCAD to update changes to the display, in addition to calling EnableGraphicsFlush() and QueueForGraphicsFlush()
If you're using Transient graphics, you can try one of Kean's hacks that is supposed to force AutoCAD to process any pending window messages (I haven't tried this so I can't vouch for it):
// Using System.Windows.Forms; // Using System.Drawing; Point p = Cursor.Position; Cursor.Position = new Point(p.X, p.Y);
Another thing yhou can try is calling the undocumented Autodesk.AutoCAD.Internal.Utils.FlushGraphics() method.
If you're modifying objects in the database, you will need to commit the transaction in which the changes were made to those objects You can use nested transactions to periodically update graphics without making the individual changes in each nested transaction undoable.
Re : Redrawing the screen during execution of a Command Method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thank you! That worked. The final answer was, I had to do everything suggested above. I committed the transaction periodically, and upon the commit my C# code looks like
_document.TransactionManager.EnableGraphicsFlush(t
_document.TransactionManager.QueueForGraphicsFlush
Autodesk.AutoCAD.Internal.Utils.FlushGraphics();
_transaction.Commit();
_transaction.Dispose();
where _document and _transaction are just the usual Autocad objects I assigned to member variables of a utility class.

