<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to determine when a document is completely loaded in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684620#M65392</link>
    <description>None of the techniques that I have shown here actually work correctly. If you use the QSAVE command to save a document, rather than calling Document.AcadDocument.Save(), AutoCAD will not crash, but the changes will not actually be saved (at least not during the EndOpen event). I have tested with commands running in the application context (Session mode) as well as commands running in the document context, and the issues are the same in both cases. I have tried every event related to opening a document on the Application and DocumentCollection objects (as well as their interop equivalents), and none of them allowed me to do all the things I need to do.&lt;BR /&gt;
&lt;BR /&gt;
I am at least able to set custom properties while handling the EndOpen event, but cannot actually save them. As a matter of fact, even if I modify the properties during the EndOpen event and don't save, AutoCAD doesn't even see this as a change and never prompts to save the file when it is closed. As far as I can tell, there doesn't appear to be any particular event that a developer can handle where you will be certain a document has been completely loaded and can be modified and saved.&lt;BR /&gt;
&lt;BR /&gt;
I'm not really sure how one would even make the determination that a document is completely loaded. Could you check the lock mode? When binding to the LockModeChanged event, it seems that this event is fired dozens of times when a document is opened, though for the life of me I have no idea why. How about a DocumentCollection.DocumentLoaded or DocumentCollection.DocumentLoadComplete event in the next iteration of the .NET API?</description>
    <pubDate>Wed, 19 May 2010 18:58:46 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-05-19T18:58:46Z</dc:date>
    <item>
      <title>How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684614#M65386</link>
      <description>After several days of navigating the Object ARX .NET API documentation, I have yet to find a "good" way to determine when a document that is opened via Application.DocumentManager.Open() has been completely loaded. I was a bit surprised to find that there is no event for a Document object that will be fired once the document is completely loaded&lt;BR /&gt;
&lt;BR /&gt;
In my case, I need to update custom properties and automatically save the document (which I am currently doing by running the "QSAVE" command). My custom command is running in "Session" mode (CommandFlags.Session), because it must open a new document and then make changes to this new document. This is my first ObjectArx app, so I have no idea if DocumentCollection.Open() is usually executed asynchronously or if it is only because my command is running in session mode.&lt;BR /&gt;
&lt;BR /&gt;
I originally attempted to implement this functionality by handling the Application.DocumentManager.DocumentCreated event. However, when attempting to execute a command for an opening/loading document at this phase, the ObjectARX API throws an exception. I later decided to go outside the .NET wrapper API and take a look directly at the COM-interop assembly, where I came across the AcadApplication.EndOpen event. It turns out that I can both populate custom properties and save a document when this event is triggered. However, this event does not provide a document object in its Event arguments, only the path to the drawing. Since the same drawing can be opened multiple times, how do you narrow this down to an individual document?&lt;BR /&gt;
&lt;BR /&gt;
I am hoping that someone can provide a better solution, or suggestion, for determining when a drawing has been completely loaded, and how to also retrieve the Document object (either from the managed wrapper API or Interop API) that corresponds to the drawing that was opened.</description>
      <pubDate>Tue, 18 May 2010 15:52:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684614#M65386</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-18T15:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684615#M65387</link>
      <description>if I am reading what you are doing correctly this should get you what you are looking for I think..&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
        &lt;COMMANDMETHOD&gt; Public Sub BatchFiles()&lt;BR /&gt;
&lt;BR /&gt;
        Dim acDialog As New System.Windows.Forms.OpenFileDialog&lt;BR /&gt;
        If acDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then&lt;BR /&gt;
            For Each i As String In acDialog.FileNames&lt;BR /&gt;
                Dim acDocMgr As DocumentCollection = Application.DocumentManager&lt;BR /&gt;
                Dim acDoc As Document = acDocMgr.Open(i, True)&lt;BR /&gt;
                'you now have the current document to work with &lt;BR /&gt;
                acDoc.CloseAndDiscard()&lt;BR /&gt;
            Next&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
Edited by: mike.wohletz on May 18, 2010 6:41 PM

Edited by: mike.wohletz on May 18, 2010 6:44 PM&lt;/COMMANDMETHOD&gt;</description>
      <pubDate>Tue, 18 May 2010 23:36:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684615#M65387</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2010-05-18T23:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting when DocumentManager.Open() has completed</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684616#M65388</link>
      <description>Move the code for everything that you must do in the&lt;BR /&gt;
open document to a seperate method and apply the&lt;BR /&gt;
CommandMethod attribute to that method, *without*&lt;BR /&gt;
the CommandFlags.Session flag.&lt;BR /&gt;
&lt;BR /&gt;
Immediately after you call the Open() method, use&lt;BR /&gt;
the DocumentCollection's SendStringToExecute()&lt;BR /&gt;
method to execute the command method.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2011&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;JHOLZER&gt; wrote in message news:6393082@discussion.autodesk.com...&lt;BR /&gt;
I am currently working on an ObjectARX .NET application, and this application &lt;BR /&gt;
has a command that downloads a file from a remote server, opens the local file &lt;BR /&gt;
as a new document, and then it should write to the document's custom properties &lt;BR /&gt;
to store information about the remote server where the file originated from.&lt;BR /&gt;
&lt;BR /&gt;
The problem I am having is that I am getting an eLockViolation error when trying &lt;BR /&gt;
to update the custom properties, because the call to &lt;BR /&gt;
Application.DocumentManager.Open() is asynchronous and is not complete when I am &lt;BR /&gt;
attempting to update the custom properties. I should mention that the command &lt;BR /&gt;
which does all this work is being executed in Session mode &lt;BR /&gt;
(CommandFlags.Session), since the command will be executed on one drawing and &lt;BR /&gt;
then must be able to open a new drawing and manipulate it.&lt;BR /&gt;
&lt;BR /&gt;
I have tried handling various events on the DocumentCollection (DocumentCreated, &lt;BR /&gt;
DocumentLockModeChanged), but none of them seem to really be what I'm looking &lt;BR /&gt;
for. I would like to be able to detect when the call to &lt;BR /&gt;
Application.DocumentManager.Open() has completed so that I can then make changes &lt;BR /&gt;
to it (if it's writable).&lt;/JHOLZER&gt;</description>
      <pubDate>Wed, 19 May 2010 00:32:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684616#M65388</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-19T00:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684617#M65389</link>
      <description>Mike,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the reply. Your code unfortunately will not solve the issue that I have. My issue is that the call to Application.DocumentManager.Open() is asynchronous, at least when you run a command in the application scope (CommandFlags.Session). That is, when you call Open(), it will return before the document is completely loaded. Therefore, if you immediately attempt to modify and save the document, which in my case I am doing (setting custom properties and saving), AutoCAD will throw an error that is basically saying something to the effect of "the document is not currently in a state where it can be modified".&lt;BR /&gt;
&lt;BR /&gt;
I have solved the problem, in a manner of speaking, by using the EndOpen event that is available on the Application.AcadApplication COM object. However, a major downside to using this event is that it only provides the path of the document that was opened, rather than a document object that would allow you to determine exactly which document was opened.&lt;BR /&gt;
&lt;BR /&gt;
So, for example, this code would fail (sorry if you don't know C#. I don't do VB)&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
[CommandMethod("OpenAndModify", CommandFlags.Session | CommandFlags.Modal)]&lt;BR /&gt;
public void OpenAndModify()&lt;BR /&gt;
{&lt;BR /&gt;
    // attempt to open read-write&lt;BR /&gt;
    var document = Application.DocumentManager.Open("somfile.dwg", false);&lt;BR /&gt;
&lt;BR /&gt;
    // modify a custom property&lt;BR /&gt;
    var infoBuilder = new DatabaseSummaryInfoBuilder(document.Database.SummaryInfo);&lt;BR /&gt;
    infoBuilder.CustomPropertyTable["foo"] = "bar";&lt;BR /&gt;
&lt;BR /&gt;
    // write the changes back to the document/database (this will likely fail)&lt;BR /&gt;
    document.Database.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();&lt;BR /&gt;
&lt;BR /&gt;
    // if the above line didn't throw an exception, this one almost certainly will&lt;BR /&gt;
    ((AcadDocument)document.AcadDocument).Save();&lt;BR /&gt;
}&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
However, an example such as the one below would work and achieve the result desired in the first example.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
[CommandMethod("OpenAndModify", CommandFlags.Session | CommandFlags.Modal)]&lt;BR /&gt;
public void OpenAndModify()&lt;BR /&gt;
{&lt;BR /&gt;
    var comApplication = (AcadApplication) Application.AcadApplication;&lt;BR /&gt;
    comApplication.EndOpen += EndOpenHandler;&lt;BR /&gt;
&lt;BR /&gt;
    // attempt to open read-write&lt;BR /&gt;
    var document = Application.DocumentManager.Open("somfile.dwg", false);&lt;BR /&gt;
&lt;BR /&gt;
    // make document active so that we can easily retrieve it in the event handler&lt;BR /&gt;
    Application.DocumentManager.MdiActiveDocument = document;&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
// handles the AcadApplication.EndOpen event&lt;BR /&gt;
private void EndOpenHandler(String filename)&lt;BR /&gt;
{&lt;BR /&gt;
    // if we didn't make the document active previously, this wouldn't work&lt;BR /&gt;
    var document = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;
&lt;BR /&gt;
    // modify a custom property&lt;BR /&gt;
    var infoBuilder = new DatabaseSummaryInfoBuilder(document.Database.SummaryInfo);&lt;BR /&gt;
    infoBuilder.CustomPropertyTable["foo"] = "bar";&lt;BR /&gt;
&lt;BR /&gt;
    // write the changes back to the document/database (this will likely fail)&lt;BR /&gt;
    document.Database.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();&lt;BR /&gt;
&lt;BR /&gt;
    // if the above line didn't throw an exception, this one almost certainly will&lt;BR /&gt;
    ((AcadDocument)document.AcadDocument).Save();&lt;BR /&gt;
}&lt;BR /&gt;
{code}</description>
      <pubDate>Wed, 19 May 2010 14:46:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684617#M65389</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-19T14:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting when DocumentManager.Open() has completed</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684618#M65390</link>
      <description>{quote}&lt;BR /&gt;
Move the code for everything that you must do in the open document to a seperate method and apply the CommandMethod attribute to that method, *without* the CommandFlags.Session flag.&lt;BR /&gt;
&lt;BR /&gt;
Immediately after you call the Open() method, use the DocumentCollection's SendStringToExecute() method to execute the command method.&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
Tony,&lt;BR /&gt;
&lt;BR /&gt;
Thank you for the reply, but I'm afraid I don't see how this would resolve the issue. First off, SendStringToExecute is an instance method of the Document class, not DocumentCollection, and part of my problem was precisely that I could not run a command against the opened document immediately after calling DocumentCollection.Open() .&lt;BR /&gt;
&lt;BR /&gt;
For the time being, the only viable option I've found is using the EndOpen event that's only available on the AcadApplication COM object (why this event is not available in the .NET wrapper API I have no idea). As previously mentioned, I wish this event provided a document object rather than a path, but as the overused cliché goes, "it is what it is." For my application, I am able to simply "activate" the document immediately after it's opened, and then use the DocumentCollection.MdiActiveDocument property to access it in the EndOpen event handler. This feels like a bit of a hack, but it's the best solution I've been able to find thus far.

Edited by: jholzer on May 19, 2010 10:58 AM</description>
      <pubDate>Wed, 19 May 2010 14:56:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684618#M65390</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-19T14:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684619#M65391</link>
      <description>I should also add that when handling an event on an object that will persist for the life of your application (i.e. the Application or Application.DocumentManager objects), you will want to make sure an additional event handler is not added each time a command is executed. To ensure this doesn't happen, you have to unbind the event handler from the event once it's done with whatever tasks it needs to do. Otherwise, each time you run a command, you will add an additional event handler and it will end up executing the same handler method over and over, the number of executions increasing the more times you run the command.&lt;BR /&gt;
&lt;BR /&gt;
For instance, if you wanted to handle the DocumentCollection.DocumentCreated event from a command, you would need to do something like the following to make sure you aren't executing the same handler method mutliple times when you run a command more than once.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
[CommandMethod("foo", CommandFlags.Modal | CommandFlags.Session)]&lt;BR /&gt;
public void Foo()&lt;BR /&gt;
{&lt;BR /&gt;
    // Adds a new event handler each time the command is run.&lt;BR /&gt;
    // If this handler is not unbound, then when you run the command&lt;BR /&gt;
    // for the 2nd time, this handler will be executed 2 times, on the 5th&lt;BR /&gt;
    // run 5 times, 100th run 100 times, and so on.&lt;BR /&gt;
    Application.DocumentManager.DocumentCreated += HandleDocumentCreated;&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
private void HandleDocumentCreated(Object sender, DocumentCollectionEventArgs args)&lt;BR /&gt;
{&lt;BR /&gt;
    // handle the event&lt;BR /&gt;
    ...&lt;BR /&gt;
&lt;BR /&gt;
    // Unbind this handler.&lt;BR /&gt;
    // Otherwise, it will be executed multiple times&lt;BR /&gt;
    // for each additional time you execute the "foo" command&lt;BR /&gt;
    Application.DocumentManager.DocumentCreated -= HandleDocumentCreated;&lt;BR /&gt;
}&lt;BR /&gt;
{code}

Edited by: jholzer on May 19, 2010 11:47 AM</description>
      <pubDate>Wed, 19 May 2010 15:45:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684619#M65391</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-19T15:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684620#M65392</link>
      <description>None of the techniques that I have shown here actually work correctly. If you use the QSAVE command to save a document, rather than calling Document.AcadDocument.Save(), AutoCAD will not crash, but the changes will not actually be saved (at least not during the EndOpen event). I have tested with commands running in the application context (Session mode) as well as commands running in the document context, and the issues are the same in both cases. I have tried every event related to opening a document on the Application and DocumentCollection objects (as well as their interop equivalents), and none of them allowed me to do all the things I need to do.&lt;BR /&gt;
&lt;BR /&gt;
I am at least able to set custom properties while handling the EndOpen event, but cannot actually save them. As a matter of fact, even if I modify the properties during the EndOpen event and don't save, AutoCAD doesn't even see this as a change and never prompts to save the file when it is closed. As far as I can tell, there doesn't appear to be any particular event that a developer can handle where you will be certain a document has been completely loaded and can be modified and saved.&lt;BR /&gt;
&lt;BR /&gt;
I'm not really sure how one would even make the determination that a document is completely loaded. Could you check the lock mode? When binding to the LockModeChanged event, it seems that this event is fired dozens of times when a document is opened, though for the life of me I have no idea why. How about a DocumentCollection.DocumentLoaded or DocumentCollection.DocumentLoadComplete event in the next iteration of the .NET API?</description>
      <pubDate>Wed, 19 May 2010 18:58:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684620#M65392</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-19T18:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting when DocumentManager.Open() has completed</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684621#M65393</link>
      <description>-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2011&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;JHOLZER&gt; wrote in message news:6393769@discussion.autodesk.com...&lt;BR /&gt;
{quote}&lt;BR /&gt;
Move the code for everything that you must do in the open document to a seperate &lt;BR /&gt;
method and apply the CommandMethod attribute to that method, *without* the &lt;BR /&gt;
CommandFlags.Session flag.&lt;BR /&gt;
&lt;BR /&gt;
Immediately after you call the Open() method, use the DocumentCollection's &lt;BR /&gt;
SendStringToExecute() method to execute the command method.&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
Tony,&lt;BR /&gt;
&lt;BR /&gt;
Thank you for the reply, but I'm afraid I don't see how this would resolve the &lt;BR /&gt;
issue. First off, SendStringToExecute is an instance method of the Document &lt;BR /&gt;
class, not DocumentCollection, and part of my problem was precisely that I could &lt;BR /&gt;
not run a command against the opened document immediately after calling &lt;BR /&gt;
DocumentCollection.Open() .&lt;BR /&gt;
&lt;BR /&gt;
For the time being, the only viable option I've found is using the EndOpen event &lt;BR /&gt;
that's only available on the AcadApplication COM object (why this event is not &lt;BR /&gt;
available in the .NET wrapper API I have no idea). As previously mentioned, I &lt;BR /&gt;
wish this event provided a document object rather than a path, but as the &lt;BR /&gt;
overused cliché goes, "it is what it is." For my application, I am able to &lt;BR /&gt;
simply "activate" the document immediately after it's opened, and then use the &lt;BR /&gt;
DocumentCollection.MdiActiveDocument property to access it in the EndOpen event &lt;BR /&gt;
handler. This feels like a bit of a hack, but it's the best solution I've been &lt;BR /&gt;
able to find thus far.&lt;BR /&gt;
&lt;BR /&gt;
Edited by: jholzer on May 19, 2010 10:58 AM&lt;/JHOLZER&gt;</description>
      <pubDate>Wed, 19 May 2010 21:07:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684621#M65393</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-19T21:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684622#M65394</link>
      <description>Are you speculating that SendStringToExecute() will&lt;BR /&gt;
not work after calling Open() or have you actually tried it?&lt;BR /&gt;
&lt;BR /&gt;
Is your purpose in opening documents only to modify&lt;BR /&gt;
their summary information?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2011&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;JHOLZER&gt; wrote in message news:6394004@discussion.autodesk.com...&lt;BR /&gt;
None of the techniques that I have shown here actually work correctly. If you &lt;BR /&gt;
use the QSAVE command to save a document, rather than calling &lt;BR /&gt;
Document.AcadDocument.Save(), AutoCAD will not crash, but the changes will not &lt;BR /&gt;
actually be saved (at least not during the EndOpen event). I have tested with &lt;BR /&gt;
commands running in the application context (Session mode) as well as commands &lt;BR /&gt;
running in the document context, and the issues are the same in both cases. I &lt;BR /&gt;
have tried every event related to opening a document on the Application and &lt;BR /&gt;
DocumentCollection objects (as well as their interop equivalents), and none of &lt;BR /&gt;
them allowed me to do all the things I need to do.&lt;BR /&gt;
&lt;BR /&gt;
I am at least able to set custom properties while handling the EndOpen event, &lt;BR /&gt;
but cannot actually save them. As a matter of fact, even if I modify the &lt;BR /&gt;
properties during the EndOpen event and don't save, AutoCAD doesn't even see &lt;BR /&gt;
this as a change and never prompts to save the file when it is closed. As far as &lt;BR /&gt;
I can tell, there doesn't appear to be any particular event that a developer can &lt;BR /&gt;
handle where you will be certain a document has been completely loaded and can &lt;BR /&gt;
be modified and saved.&lt;BR /&gt;
&lt;BR /&gt;
I'm not really sure how one would even make the determination that a document is &lt;BR /&gt;
completely loaded. Could you check the lock mode? When binding to the &lt;BR /&gt;
LockModeChanged event, it seems that this event is fired dozens of times when a &lt;BR /&gt;
document is opened, though for the life of me I have no idea why. How about a &lt;BR /&gt;
DocumentCollection.DocumentLoaded or DocumentCollection.DocumentLoadComplete &lt;BR /&gt;
event in the next iteration of the .NET API?&lt;/JHOLZER&gt;</description>
      <pubDate>Wed, 19 May 2010 21:07:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684622#M65394</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-19T21:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684623#M65395</link>
      <description>Both of the methodes that have been supplied will work, I have done and tested this and it works and I know that Tony's method will also work..&lt;BR /&gt;
&lt;BR /&gt;
vb.net code "you can convert it"&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
   &lt;COMMANDMETHOD&gt; Public Sub BatchFiles()&lt;BR /&gt;
&lt;BR /&gt;
        Dim acDialog As New System.Windows.Forms.OpenFileDialog&lt;BR /&gt;
        If acDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then&lt;BR /&gt;
            For Each i As String In acDialog.FileNames&lt;BR /&gt;
                Dim acDocMgr As DocumentCollection = Application.DocumentManager&lt;BR /&gt;
                Dim acDoc As Document = acDocMgr.Open(i, False)&lt;BR /&gt;
                'you now have the current document to work with &lt;BR /&gt;
                Using doclock As DocumentLock = acDoc.LockDocument&lt;BR /&gt;
                    Dim myInfo = New DatabaseSummaryInfoBuilder(acDoc.Database.SummaryInfo)&lt;BR /&gt;
                    myInfo.CustomProperties.Item("foo") = "bar"&lt;BR /&gt;
                    acDoc.Database.SummaryInfo = myInfo.ToDatabaseSummaryInfo&lt;BR /&gt;
                End Using&lt;BR /&gt;
              &lt;BR /&gt;
&lt;BR /&gt;
                acDoc.CloseAndSave(acDoc.Name)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
                'acDoc.CloseAndDiscard()&lt;BR /&gt;
            Next&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
Edited by: mike.wohletz on May 19, 2010 7:21 PM&lt;BR /&gt;
see attached for good code, post messes it up

Edited by: mike.wohletz on May 20, 2010 7:29 AM&lt;/COMMANDMETHOD&gt;</description>
      <pubDate>Thu, 20 May 2010 00:17:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684623#M65395</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2010-05-20T00:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684624#M65396</link>
      <description>{quote}&lt;BR /&gt;
Are you speculating that SendStringToExecute() will not work after calling Open() or have you actually tried it?&lt;BR /&gt;
{quote}&lt;BR /&gt;
I am not speculating or even trying to insinuate that this is the case. Now, if I attempt to call SendStringToExectue immediately after calling DocumentCollection.Open then it won't work. However, if I call SendStringToExecute from the EndOpen event handler, it certainly works fine. In my case, I was originally attempting to save a file using the QSAVE command, and while the command would appear to execute without issue, nothing actually got saved. I also attempted to use the Document.Database.SaveAs() method, with the exact same result (code ran fine, but nothing was actually saved).&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
{quote}&lt;BR /&gt;
Is your purpose in opening documents only to modify their summary information?&lt;BR /&gt;
{quote}&lt;BR /&gt;
No, this is only one step in the process for "opening" a file. Essentially what I would like to happen is:&lt;BR /&gt;
&lt;BR /&gt;
  1. The file is downloaded from the remote server (this is working fine)&lt;BR /&gt;
  2. The file is opened in AutoCAD and made the active document&lt;BR /&gt;
  3. Custom properties are set on the opened file to store information about where it originated from on the remote server&lt;BR /&gt;
  4. The document is automatically saved after the custom properties are set, but remains open and active</description>
      <pubDate>Thu, 20 May 2010 14:13:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684624#M65396</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-20T14:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684625#M65397</link>
      <description>I have not tried using the LockDocument method, so I will give that a shot and see if perhaps that was my problem.</description>
      <pubDate>Thu, 20 May 2010 14:16:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684625#M65397</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-20T14:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684626#M65398</link>
      <description>Mike,&lt;BR /&gt;
&lt;BR /&gt;
It turns out that locking the document did the trick. Thanks for the code sample. I don't know if I ever would have figured out that was the problem.&lt;BR /&gt;
&lt;BR /&gt;
As a general rule of thumb, should you lock any time you wish to make changes to a document?</description>
      <pubDate>Thu, 20 May 2010 14:42:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684626#M65398</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-20T14:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine when a document is completely loaded</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684627#M65399</link>
      <description>{quote}&lt;BR /&gt;
&lt;BR /&gt;
Now, if I attempt to call SendStringToExectue immediately after&lt;BR /&gt;
calling DocumentCollection.Open then it won't work.&lt;BR /&gt;
&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
You're mistaken on all counts.&lt;BR /&gt;
&lt;BR /&gt;
  -  DocumentCollection.Open() is NOT asnynchronous&lt;BR /&gt;
&lt;BR /&gt;
  -  Document.SendStringToExecute() works after calling Open().&lt;BR /&gt;
&lt;BR /&gt;
Your code was not calling SendStringToExecute() with the&lt;BR /&gt;
correct parameters, which is what causes the eInvalidInput&lt;BR /&gt;
error.&lt;BR /&gt;
&lt;BR /&gt;
If all you are doing is modifying the summary information, then&lt;BR /&gt;
you're going about it incorrectly to start with.&lt;BR /&gt;
&lt;BR /&gt;
What you should be doing is opening the drawing file externally&lt;BR /&gt;
using Database.ReadDwgFile(), modify the summary information,&lt;BR /&gt;
and then use Database.SaveAs() to save the file. After you do&lt;BR /&gt;
that, you only need to open the file the editor and exit.&lt;BR /&gt;
&lt;BR /&gt;
While the kludge you're using will work for cases where you&lt;BR /&gt;
are only modifying the drawing via API calls, it will not work&lt;BR /&gt;
in cases where you need to execute AutoCAD commands (as&lt;BR /&gt;
many batch processing scenarios need to do).&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2011&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;JHOLZER&gt; wrote in message news:6394446@discussion.autodesk.com...&lt;BR /&gt;
{quote}&lt;BR /&gt;
Are you speculating that SendStringToExecute() will not work after calling&lt;BR /&gt;
Open() or have you actually tried it?&lt;BR /&gt;
{quote}&lt;BR /&gt;
I am not speculating or even trying to insinuate that this is the case. Now, if&lt;BR /&gt;
I attempt to call SendStringToExectue immediately after calling&lt;BR /&gt;
DocumentCollection.Open then it won't work. However, if I call&lt;BR /&gt;
SendStringToExecute from the EndOpen event handler, it certainly works fine. In&lt;BR /&gt;
my case, I was originally attempting to save a file using the QSAVE command, and&lt;BR /&gt;
while the command would appear to execute without issue, nothing actually got&lt;BR /&gt;
saved. I also attempted to use the Document.Database.SaveAs() method, with the&lt;BR /&gt;
exact same result (code ran fine, but nothing was actually saved).&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
{quote}&lt;BR /&gt;
Is your purpose in opening documents only to modify their summary information?&lt;BR /&gt;
{quote}&lt;BR /&gt;
No, this is only one step in the process for "opening" a file. Essentially what&lt;BR /&gt;
I would like to happen is:&lt;BR /&gt;
&lt;BR /&gt;
  1. The file is downloaded from the remote server (this is working fine)&lt;BR /&gt;
  2. The file is opened in AutoCAD and made the active document&lt;BR /&gt;
  3. Custom properties are set on the opened file to store information about&lt;BR /&gt;
where it originated from on the remote server&lt;BR /&gt;
  4. The document is automatically saved after the custom properties are set,&lt;BR /&gt;
but remains open and active&lt;/JHOLZER&gt;</description>
      <pubDate>Thu, 20 May 2010 19:01:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-determine-when-a-document-is-completely-loaded/m-p/2684627#M65399</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-05-20T19:01:27Z</dc:date>
    </item>
  </channel>
</rss>

