Author Topic: Opening Multiple Databases  (Read 2815 times)

0 Members and 1 Guest are viewing this topic.

smcclure

  • Guest
Opening Multiple Databases
« on: January 19, 2007, 11:16:11 AM »
Hi,

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.

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:
Quote
"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."

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.

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.

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.

Code: [Select]
            Try
                'Using dbDoc As Document = Application.DocumentManager.Open(dwgPath, True)
                Using db As Database = New Autodesk.AutoCAD.DatabaseServices.Database(False, True)
                    MsgBox("Adding " & dwgPath & "...")
                    db.ReadDwgFile(dwgPath, System.IO.FileShare.Read, True, Nothing)
                    Dim dbDoc As Document = Application.DocumentManager.GetDocument(db)

                    If dbDoc IsNot Nothing Then MsgBox("DB Path: " & db.Filename & ", Doc Path:" & dbDoc.Name)
                End Using
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try

Chuck Gabriel

  • Guest
Re: Opening Multiple Databases
« Reply #1 on: January 19, 2007, 12:33:07 PM »
If I understand your question, I think you are on a wild goose chase.

Editor methods are not applicable when you are working on a database that is not open in the editor (i.e. the database has no document associated with it).

However, you can iterate over the database fairly quickly, so not having selection set functionality available is little more than a nuisance.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Opening Multiple Databases
« Reply #2 on: January 19, 2007, 06:27:30 PM »
I had some problems with processing multiple files until I made my dialog modeless.
I wonder if that would help you.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions