<?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 Opening Multiple Databases in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/opening-multiple-databases/m-p/1867676#M79258</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I am attempting to open a database, create a filtered selection set, iterate through the results, close the document, and then open another. Since I am using SelectionSets, I need to get access to the Editor, which is in the document. I thought the proper way to do this was a call to Application.DocumentManager.GetDocument(myDB), but when I compare the Document.Name to the Database.Filename, I find that the document I just retrieved has the path of the MDI active document, not the database. &lt;BR /&gt;
&lt;BR /&gt;
After looking through my code, I suspected an incorrect argument to the Database(buildDefaultDrawing, noDocument) constructor may be the cause. After looking through the ARX documentation, the noDocument property is described as:&lt;BR /&gt;
&lt;BR /&gt;
"Boolean specifying whether or not to associate this database to the current document... If noDocument == true, then the newly created database will not be associated with the current document; otherwise it will."&lt;BR /&gt;
&lt;BR /&gt;
My code originally set the noDocument property to false, so I tried changing it to true so the database would no longer be associated with the current document. I recieve an InvalidOperationException informing me that the object is not in the proper state when I try to execute the call to Application.DocumentManager.GetDocument.&lt;BR /&gt;
&lt;BR /&gt;
I tried modifying the code to use a call to Application.DocumentManager.Open instead, but this recieved an error that the operation could not be executed due to an invalid context. This immediately made me think about a possible Application/Document context issue, so I checked again, and the registered command method uses the Session command flag. One possibility which I am unsure of is if the execution context changes by launching a modal form using Application.ShowModalDialog, since the code is actually contained in a dialog launched from the command method.&lt;BR /&gt;
&lt;BR /&gt;
Does anybody have any suggestions on how to either properly retrieve the document for a database, or retrieve the document in the first place? A code snippet illustrating what I am doing is below.&lt;BR /&gt;
[code]&lt;BR /&gt;
            Try&lt;BR /&gt;
                'Using dbDoc As Document = Application.DocumentManager.Open(dwgPath, True)&lt;BR /&gt;
                Using db As Database = New Autodesk.AutoCAD.DatabaseServices.Database(False, True)&lt;BR /&gt;
                    MsgBox("Adding " &amp;amp; dwgPath &amp;amp; "...")&lt;BR /&gt;
                    db.ReadDwgFile(dwgPath, System.IO.FileShare.Read, True, Nothing)&lt;BR /&gt;
                    Dim dbDoc As Document = Application.DocumentManager.GetDocument(db)&lt;BR /&gt;
&lt;BR /&gt;
                    If dbDoc IsNot Nothing Then MsgBox("DB Path: " &amp;amp; db.Filename &amp;amp; ", Doc Path:" &amp;amp; dbDoc.Name)&lt;BR /&gt;
                End Using&lt;BR /&gt;
            Catch ex As Exception&lt;BR /&gt;
                MsgBox(ex.ToString)&lt;BR /&gt;
            End Try&lt;BR /&gt;
[/code]</description>
    <pubDate>Fri, 19 Jan 2007 16:58:13 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2007-01-19T16:58:13Z</dc:date>
    <item>
      <title>Opening Multiple Databases</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-multiple-databases/m-p/1867676#M79258</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I am attempting to open a database, create a filtered selection set, iterate through the results, close the document, and then open another. Since I am using SelectionSets, I need to get access to the Editor, which is in the document. I thought the proper way to do this was a call to Application.DocumentManager.GetDocument(myDB), but when I compare the Document.Name to the Database.Filename, I find that the document I just retrieved has the path of the MDI active document, not the database. &lt;BR /&gt;
&lt;BR /&gt;
After looking through my code, I suspected an incorrect argument to the Database(buildDefaultDrawing, noDocument) constructor may be the cause. After looking through the ARX documentation, the noDocument property is described as:&lt;BR /&gt;
&lt;BR /&gt;
"Boolean specifying whether or not to associate this database to the current document... If noDocument == true, then the newly created database will not be associated with the current document; otherwise it will."&lt;BR /&gt;
&lt;BR /&gt;
My code originally set the noDocument property to false, so I tried changing it to true so the database would no longer be associated with the current document. I recieve an InvalidOperationException informing me that the object is not in the proper state when I try to execute the call to Application.DocumentManager.GetDocument.&lt;BR /&gt;
&lt;BR /&gt;
I tried modifying the code to use a call to Application.DocumentManager.Open instead, but this recieved an error that the operation could not be executed due to an invalid context. This immediately made me think about a possible Application/Document context issue, so I checked again, and the registered command method uses the Session command flag. One possibility which I am unsure of is if the execution context changes by launching a modal form using Application.ShowModalDialog, since the code is actually contained in a dialog launched from the command method.&lt;BR /&gt;
&lt;BR /&gt;
Does anybody have any suggestions on how to either properly retrieve the document for a database, or retrieve the document in the first place? A code snippet illustrating what I am doing is below.&lt;BR /&gt;
[code]&lt;BR /&gt;
            Try&lt;BR /&gt;
                'Using dbDoc As Document = Application.DocumentManager.Open(dwgPath, True)&lt;BR /&gt;
                Using db As Database = New Autodesk.AutoCAD.DatabaseServices.Database(False, True)&lt;BR /&gt;
                    MsgBox("Adding " &amp;amp; dwgPath &amp;amp; "...")&lt;BR /&gt;
                    db.ReadDwgFile(dwgPath, System.IO.FileShare.Read, True, Nothing)&lt;BR /&gt;
                    Dim dbDoc As Document = Application.DocumentManager.GetDocument(db)&lt;BR /&gt;
&lt;BR /&gt;
                    If dbDoc IsNot Nothing Then MsgBox("DB Path: " &amp;amp; db.Filename &amp;amp; ", Doc Path:" &amp;amp; dbDoc.Name)&lt;BR /&gt;
                End Using&lt;BR /&gt;
            Catch ex As Exception&lt;BR /&gt;
                MsgBox(ex.ToString)&lt;BR /&gt;
            End Try&lt;BR /&gt;
[/code]</description>
      <pubDate>Fri, 19 Jan 2007 16:58:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-multiple-databases/m-p/1867676#M79258</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-19T16:58:13Z</dc:date>
    </item>
  </channel>
</rss>

