Results 1 to 4 of 4

Thread: eWasOpenForWrite

  1. #1
    Member
    Join Date
    2006-02
    Posts
    39
    Login to Give a bone
    0

    Default eWasOpenForWrite

    Hi,

    I have some code that works fine. But after I run an AutoCAD command, the code will not work. I get the error 'eWasOpenForWrite'. The reason could be, that AutoCAD has opened the drawing database for write, but did not close. What can be done in my code to tackle this problem?

    Thanks

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,495
    Login to Give a bone
    0

    Default Re: eWasOpenForWrite

    Not the database, but a single object. Show your code.
    C:> ED WORKING....


    LinkedIn

  3. #3
    Member
    Join Date
    2006-02
    Posts
    39
    Login to Give a bone
    0

    Default Re: eWasOpenForWrite

    Code:
    Public Sub BX()
            Dim bTransMan As DatabaseServices.TransactionManager
            Dim bTrans As DatabaseServices.Transaction
            Dim bDwg As Document
            Dim bBT As BlockTable
    
            Dim bBTR As SymbolTableRecord
            Dim bBTE As SymbolTableEnumerator
            Dim bBTRr As BlockTableRecord
    
            'Current Document
            bDwg = Application.DocumentManager.MdiActiveDocument
            bTransMan = bDwg.TransactionManager
    
            bTrans = bTransMan.StartTransaction
            Try
                'Open the database for Read
                bBT = bDwg.Database.BlockTableId.GetObject(OpenMode.ForRead)
                bBTE = bBT.GetEnumerator
    
                Dim XrefIds As New ObjectIdCollection
                Dim DetXIds As New ObjectIdCollection
                Dim DetXId As New ObjectId
                Dim ReXIds As New ObjectIdCollection
                Dim graphXref As XrefGraph
                Dim nodeXref As XrefGraphNode
                Dim btrId As Object
    
                graphXref = bDwg.Database.GetHostDwgXrefGraph(True)
                For idx As Integer = 1 To graphXref.NumNodes - 1
                    nodeXref = graphXref.GetXrefNode(idx)
                    If nodeXref.IsNested Then
                        Select Case nodeXref.XrefStatus
                            Case XrefStatus.FileNotFound
                                btrId = nodeXref.BlockTableRecordId
                                Dim BTR As BlockTableRecord = bTrans.GetObject(btrId, OpenMode.ForWrite)
                                BTR.PathName = "C:\1.dwg"
                                ReXIds.Add(BTR.Id)
                            Case XrefStatus.Unreferenced
                                btrId = nodeXref.BlockTableRecordId
                                Dim BTR As BlockTableRecord = bTrans.GetObject(btrId, OpenMode.ForWrite)
                                BTR.PathName = "C:\1.dwg"
                                ReXIds.Add(BTR.Id)
                            Case XrefStatus.Unloaded
                                btrId = nodeXref.BlockTableRecordId
                                Dim BTR As BlockTableRecord = bTrans.GetObject(btrId, OpenMode.ForWrite)
                                BTR.PathName = "C:\1.dwg"
                                ReXIds.Add(BTR.Id)
                            Case XrefStatus.Unresolved
                                btrId = nodeXref.BlockTableRecordId
                                Dim BTR As BlockTableRecord = bTrans.GetObject(btrId, OpenMode.ForWrite)
                                BTR.PathName = "C:\1.dwg"
                                ReXIds.Add(BTR.Id)
                        End Select
                    End If
                Next
    
                If ReXIds.Count > 0 Then
                    bDwg.Database.ReloadXrefs(ReXIds)
                End If
    
                While bBTE.MoveNext = True
                    bBTR = bBTE.Current.GetObject(OpenMode.ForRead)
                    bBTRr = CType(bBTR, BlockTableRecord)
    
                    'Check if block is xref and also resolved and then add its ID to the ObjectIdCollection
                    If bBTRr.IsFromExternalReference Then
                        Select Case bBTRr.XrefStatus
                            Case XrefStatus.Resolved
                                XrefIds.Add(bBTRr.Id)
                            Case XrefStatus.Unloaded
                                DetXIds.Add(bBTRr.Id)
                            Case XrefStatus.FileNotFound
                                DetXIds.Add(bBTRr.Id)
                            Case XrefStatus.Unreferenced
                                DetXIds.Add(bBTRr.Id)
                            Case XrefStatus.Unresolved
                                DetXIds.Add(bBTRr.Id)
                        End Select
                    End If
    
                End While
    
                'Bind xref of collection
                Try
                    'We bind all xrefs of drawing
                    If XrefIds.Count > 0 Then
                        bDwg.Database.BindXrefs(XrefIds, False)
                    End If
    
                    For Each DetXId In DetXIds
                        bDwg.Database.DetachXref(DetXId)
                    Next
    
                Catch ex As Exception
                    MsgBox("Error2: " & ex.Message)  <-----------------The error displayed is from here.
                End Try
    
                bTrans.Commit()
    
            Catch ex As Exception
                MsgBox("Error1: " & ex.Message)
            Finally
                    bTrans.Dispose()
                    bTransMan.Dispose()
            End Try
    
        End Sub
    After I use the scalelist command to reset, it doesn't work. Otherwise, it's fine.
    Last edited by Ed Jobe; 2008-04-08 at 07:02 PM. Reason: Added Code tags.

  4. #4
    Active Member
    Join Date
    2011-11
    Location
    Saint-Omer, Pas-de-Calais, France
    Posts
    58
    Login to Give a bone
    0

    Default Re: eWasOpenForWrite

    Little late, but I think it's because of the line:

    Code:
    Dim DetXId As New ObjectId
    should be

    Code:
    Dim DetXId As ObjectId
    You should never create an ObjectId.

Similar Threads

  1. puzzled! eWasOpenForWrite error
    By 289924688488291 in forum Dot Net API
    Replies: 7
    Last Post: 2024-04-17, 05:59 PM
  2. Replies: 7
    Last Post: 2009-05-26, 04:51 PM
  3. eWasOpenForWrite
    By cristiandabu in forum Dot Net API
    Replies: 1
    Last Post: 2009-01-21, 08:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •