.NET

In AutoCAD there is a getdocument in the DocumentManager (ApplicationServices.DocumentCollection). See below.

[code]
'get the document from the objectID
Dim doc As Document = Application.DocumentManager.GetDocument(objID.Database)
'and also get document from the documentcollection
Dim btr As BlockTableRecord = senderObj
Dim oDoc As Document = Application.DocumentManager.GetDocument(btr.Database)
[/code]

You could also add, open and close from this colection. Where is this functionality in BricsCAD or how could I impliment it?

Regards,
Evan

Comments

  • Ok. Work arounds for the moment.

    [code]
    'Interate through the collection to find the database.
        Private Shared Function GetDocument(db As Database) As Document
            For Each doc As Document In Application.DocumentManager
                If doc.Database Is db Then Return doc
            Next
            Return Nothing
        End Function
    [/code]

    The other function I am having to access through the ActiveX AcadDocument and AcadApplication.
  • Ok, for anyone interested I have an extension class for compatibility with autocad at the moment.  See below. The one problem I am having is if the document from a database i.e.
    [code]
    Dim fileName as string=""           
    Dim dbnew As Database = New Database(False, False)

                dbnew.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndWriteNoShare, True, "")
                ' closing the input makes sure the whole dwg is read from disk
                ' it also closes the file so you can SaveAs the same name
                dbnew.CloseInput(True)
                Dim ndoc As Document = Application.DocumentManager.GetDocument(dbnew)
    [/code]

    It appears that the document is not added to the DocumentCollection. So how do you get the document from the database? Any help would be appreciated.

    [code]
    Imports System.Runtime.CompilerServices
    Imports Bricscad.ApplicationServices
    Imports BricscadApp
    Imports Teigha.DatabaseServices

    Module DocumentCollectionExtensions

        _
        Public Function Open(manager As DocumentCollection, filename As String) As Document
            Return Open(manager, filename, False, Nothing)
        End Function


       
        Public Function Open(manager As DocumentCollection, fileName As String, forReadOnly As Boolean) As Document
            Return Open(manager, fileName, forReadOnly, Nothing)
        End Function

       
        Public Function Open(docCol As DocumentCollection, fileName As String, forReadOnly As Boolean, password As String) As Document
            'Member of Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension
            Dim app As AcadApplication = TryCast(Application.AcadApplication, AcadApplication)
            Dim AcadDoc As AcadDocument = app.Documents.Open(fileName, forReadOnly, password)
            If AcadDoc IsNot Nothing Then
                app.ActiveDocument = AcadDoc
                Return Bricscad.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Else
                Return Nothing
            End If
        End Function

       
        Public Function GetDocument(docCol As DocumentCollection, db As Database) As Document
            'Interate through the collection to find the database.
            For Each doc As Document In docCol
                If doc.Database = db Then
                    Return doc
                End If
            Next
            Return Nothing
        End Function

       
        Public Function Add(docCol As DocumentCollection, templateFileName As String) As Document
            'Member of Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension
            Dim app As AcadApplication = TryCast(Application.AcadApplication, AcadApplication)
            Dim AcadDoc As AcadDocument = app.Documents.Add(templateFileName)
            If AcadDoc IsNot Nothing Then
                For Each doc As Document In docCol
                    If doc.AcadDocument Is AcadDoc Then
                        Return doc
                    End If
                Next
                Return Nothing
            Else
                Return Nothing
            End If
        End Function

    End Module
    [/code]
This discussion has been closed.