.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Opening Multiple Databases

0 REPLIES 0
Reply
Message 1 of 1
smcclure
264 Views, 0 Replies

Opening Multiple Databases

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:

"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]
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
[/code]
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost