- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I've got a pretty nasty problem with AutoCAD .NET API. I want to programmatically open every drawing in project, run some commands inside, like AUDIT and then save and close.
I've tried Editor.Command() and also Document.SendStringToExecute().
SendStringToExecute is asynchronous so I gave up on this for a while because I wasn't able to force it do work as intended. I would like to send commands, then wait for them to execute and then save and close drawing. I've tried Document.CommandEnded event but to be honest it was the only idea that came to my mind:
foreach (var file in files)
{
using (var doc = docMgr.Open(file, false, ""))
{
var ready = false;
doc.CommandEnded += (sender, e) =>
{
(sender as Document).CloseAndDiscard();
ready = true;
};
doc.SendStringToExecute("DWGNAME",true, false, true);
while (!ready)
Thread.Sleep(100);
}
}
It just stops on a while loop and don't go any further.
The other approach was to use Editor.Command(). That's what I use:
foreach (var file in files)
{
using (var doc = docMgr.Open(file, false, ""))
{
doc.Editor.Command("DWGNAME");
doc.CloseAndDiscard();
}
}
But now all it does is to run the command in one document, the document I run the command from. And it logs it's document name. I'm aware that Editor.Command() works only in document's context so I've tried to set the active document by
Application.DocumentManager.MdiActiveDocument = doc
But then I got an error "Invalid input".
What an I missing? How can I wait until SendStringToExecute stops working or how can I access Editor of a document I've just opened? And I know that now I don't save my document, these snippets are just for testing.
I don't use any flags btw, I've read that Editor doesn't work with CommandFlags.Session.
Or maybe I can do this without opening document with Database.ReadDwgFile()? But then I don't have access to Editor.
Thanks in advance!
Przemek
Solved! Go to Solution.