<?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 Re: ReadDwgFile eNotOpenForWrite in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/5174683#M63619</link>
    <description>&lt;P&gt;I am trying to do saveAs from a file created from the most current version of autocad to 2010 version and i am getting a save error message of Warning: Error occured during save. We recommend that you run recover on the drawing.&lt;/P&gt;&lt;P&gt;here is my code&lt;BR /&gt;newDB.ReadDwgFile("C:\\MyDrawing\\Mass Haul-2_update2.dwg", FileOpenMode.OpenForReadAndAllShare, true, null);&lt;BR /&gt;newDB.SaveAs("C:\\MyDrawing\\Mass Haul-2_update22.dwg", DwgVersion.AC1024);&lt;/P&gt;&lt;P&gt;the new file would still be created though.&lt;/P&gt;&lt;P&gt;But if i open the original file and just do the saveas on the autocad menu , no errors encountered.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Jul 2014 21:50:36 GMT</pubDate>
    <dc:creator>mchan01</dc:creator>
    <dc:date>2014-07-24T21:50:36Z</dc:date>
    <item>
      <title>ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790100#M63609</link>
      <description>&lt;P&gt;I have been diving as deeply as I can into objectarx and .net over the last few weeks, and I ran into another "That didn't work like I expected' issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is more of a test than anything else, but I am trying to open a drawing with ReadDwgFile and then pull attribute data from a block in that drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub test()
        Dim pathtodwg As String = "C:\PlotItIn\PDB542503A4.dwg"
        Using dwg As Database = New Database(False, False)
            dwg.ReadDwgFile(pathtodwg, System.IO.FileShare.Read, True, Nothing)
            Dim db As Database = dwg.AcadDatabase
            Using Trans As Transaction = db.TransactionManager.StartTransaction&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim curblock As String = "ahlbord"
                Dim curtag As String = "REV"
                Dim bktbl As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
                Dim revblk As BlockTableRecord = bktbl(curblock).GetObject(OpenMode.ForRead)
                Dim refs As ObjectIdCollection = revblk.GetBlockReferenceIds(False, False)
                For Each ref In refs
                    Dim bref As BlockReference = Trans.GetObject(ref, OpenMode.ForRead)
                    Dim atts As AttributeCollection = bref.AttributeCollection
                    For Each obj In atts
                        Dim att As AttributeReference&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; att = Trans.GetObject(obj, OpenMode.ForRead, False)
                        If att.Tag = curtag Then
                            Application.ShowAlertDialog(att.TextString)
                        End If
                    Next
                Next
            End Using
        End Using
    End Sub



&lt;/PRE&gt;&lt;P&gt;I get the eNotOpenForWrite and AutoCAD fatals out.&amp;nbsp; I dropped some alertdialogs in to see how far it was getting and it seems like it's bombing out at the ReadDwgFile line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2010 20:38:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790100#M63609</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-06T20:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790116#M63610</link>
      <description>&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; ReadDwgFile(pathtodwg, FileOpenMode.OpenForReadAndReadShare, False, "")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2010 20:45:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790116#M63610</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-06T20:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790136#M63611</link>
      <description>&lt;P&gt;Thanks Jeffrey but That gives me the same result.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2010 20:55:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790136#M63611</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-06T20:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790172#M63612</link>
      <description>&lt;P&gt;This worked for me take the database out of the&amp;nbsp;using block, and a couple of litte changes see code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code just have to change file name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; &amp;lt;CommandMethod("Teest")&amp;gt; _
        Public Sub test()
            Dim pathtodwg As String = "C:\Users\Jeff\My Documents\test.dwg"
            Dim db As Database = New Database(False, False)
            db.ReadDwgFile(pathtodwg, System.IO.FileShare.Read, True, Nothing)
            Using Trans As Transaction = db.TransactionManager.StartTransaction
                Dim curblock As String = "ahlbord"
                Dim curtag As String = "REV"
                Dim bktbl As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
                Dim revblk As BlockTableRecord = bktbl(curblock).GetObject(OpenMode.ForRead)
                Dim refs As ObjectIdCollection = revblk.GetBlockReferenceIds(False, False)
                For Each ref In refs
                    Dim bref As BlockReference = Trans.GetObject(ref, OpenMode.ForRead)
                    Dim atts As AttributeCollection = bref.AttributeCollection
                    For Each obj In atts
                        Dim att As AttributeReference
                        att = Trans.GetObject(obj, OpenMode.ForRead, False)
                        If att.Tag = curtag Then
                            Application.ShowAlertDialog(att.TextString)
                        End If
                    Next
                Next
            End Using

        End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2010 21:14:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790172#M63612</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-06T21:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790384#M63613</link>
      <description>&lt;P&gt;I believe this is the only offending line of code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim db As Database = dwg.AcadDatabase&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can't do that, because you are taking what is already a Managed Database reference (dwg) retrieving it's COM reference (dwg.AcadDatabase) and setting that to another Managed Database variable (db).&amp;nbsp; No Can Do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error I got was not eNotOpenForWrite, so I'm not sure why you got that, but, if I take that line out of your code, and change nothing else except the strings for the filename, blockname, and&amp;nbsp;attribute tag, the code works.&amp;nbsp; (oh yeah, and replace the references to 'db' with 'dwg')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2010 00:52:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2790384#M63613</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2010-10-07T00:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2792162#M63615</link>
      <description>&lt;P&gt;Ok, I spoke too soon before.&amp;nbsp; I had it working once with the code that Jeffrey had written but when I pulled the full code together it stopped working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Function DwgQuery(ByVal pathtodwg As String)
        Dim XML_Reader As XML_Reader = New XML_Reader
        Dim XMLFile As XmlDocument
        XMLFile = XML_Reader.XMLRead _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (System.Windows.Forms.Application.StartupPath &amp;amp; "\CoverIT Config.xml")
        Dim Confignodelist As XmlNodeList = XMLFile.SelectNodes("/Blocks/Block")
        Dim revVal As String = Nothing
        Dim dateVal As String = Nothing
        Dim desc1Val As String = Nothing
        Dim desc2Val As String = Nothing
        Dim desc3Val As String = Nothing
        Dim desc4Val As String = Nothing
        Dim db As Database = New Database(False, False)
        Dim exists As Boolean = File.Exists(pathtodwg)
        db.ReadDwgFile(pathtodwg, System.IO.FileShare.Read, True, Nothing)
        Using Trans As Transaction = db.TransactionManager.StartTransaction
            Dim bktbl As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
            Dim found As Boolean = False
            For Each Confignode As XmlNode In Confignodelist
                If found = False Then
                    Dim blockname As String =Confignode.Attributes. _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetNamedItem("name").Value
                    Dim revtag As String = Confignode("Revision").Value
                    Dim datetag As String = Confignode("Date").Value
                    Dim desc1tag As String = Confignode("Desc1").Value
                    Dim desc2tag As String = Confignode("Desc2").Value
                    Dim desc3tag As String = Confignode("Desc3").Value
                    Dim desc4tag As String = Confignode("Desc4").Value
                    Dim revblk As BlockTableRecord =bktbl(blockname). _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetObject(OpenMode.ForRead)
                    Dim refs As ObjectIdCollection = revblk.GetBlockReferenceIds _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (False, False)
                    For Each ref In refs
                        Dim bref As BlockReference = Trans.GetObject(ref, OpenMode.ForRead)
                        If bref.Name = blockname Then
                            found = True
                            Dim atts As AttributeCollection = bref.AttributeCollection
                            For Each obj In atts
                                Dim att As AttributeReference = Trans.GetObject _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (obj, OpenMode.ForRead, False)
                                Select Case att.Tag
                                    Case revtag
                                        revVal = att.TextString
                                    Case datetag
                                        dateVal = att.TextString
                                    Case desc1tag
                                        desc1Val = att.TextString
                                    Case desc2tag
                                        desc2Val = att.TextString
                                    Case desc3tag
                                        desc3Val = att.TextString
                                    Case desc4tag
                                        desc4Val = att.TextString
                                End Select
                            Next
                        End If
                    Next
                End If
            Next
        End Using
        db.Dispose()
        Dim dwgpathend As Integer = pathtodwg.LastIndexOf("\")
        Dim dwgname As String = pathtodwg.Substring(dwgpathend + 1)
        Dim dwgnamelen As Integer = dwgname.Length - 4
        dwgname = dwgname.Substring(0, dwgnamelen)
        Dim result(4) As String
        result(1) = dwgname
        result(2) = revVal
        result(3) = dateVal
        result(4) = desc1Val &amp;amp; " " &amp;amp; desc2Val &amp;amp; " " &amp;amp; desc3Val &amp;amp; " " &amp;amp; desc4Val
        Return result
    End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I manually put in some line breaks so the code would fit, but this is he code I am having problems with, and it is breaking at the ReadDwgFile with the same eNotOpenForWrite.&amp;nbsp; This time the path is coming from a dialog, but I have tried both forcing the path and running a File.Exists to make sure I wasn't overlooking something obvious, and everything checked out fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There very well may be code problems further down the line but I can't get past the ReadDwgFile to work it out yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I must be missing something.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2010 15:39:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2792162#M63615</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-08T15:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2793768#M63616</link>
      <description>&lt;P&gt;I found out what I was doing wrong.&amp;nbsp; CommandFlags.Session caused the problems.&amp;nbsp; Apparently I need to read up on CommandFlags.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;</description>
      <pubDate>Mon, 11 Oct 2010 21:28:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/2793768#M63616</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-11T21:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/4768447#M63617</link>
      <description>Is there a way to open multiple dwg file in 1 editot?&lt;BR /&gt;I am using this code to read dwg file&lt;BR /&gt;Database db = doc.Database;&lt;BR /&gt;Database xdb = new Database(false, true);&lt;BR /&gt;&lt;BR /&gt;xdb.ReadDwgFile(drawingpath, FileShare.ReadWrite, true, null);&lt;BR /&gt;objid = db.Insert(blockname, xdb, true);&lt;BR /&gt;&lt;BR /&gt;on the 1st pass or the 1st dwg file it was working fine, i was able to display the dwg file. but after the 2nd, i loose control now of the 1st dwg file.</description>
      <pubDate>Wed, 22 Jan 2014 21:43:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/4768447#M63617</guid>
      <dc:creator>mchan01</dc:creator>
      <dc:date>2014-01-22T21:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/4768649#M63618</link>
      <description>&lt;P&gt;You can open multiple drawing files in a loop, assigning each to the same variable, but you must call Dispose() on each Database before you assign it to another Database.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Don't use ReadDwgFile() to read multiple .DWG files with the same Database instance, just create a new instance for each file you want to read, and be sure to call Dispose() on each, or you will run into problems.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need to concurrently work with multiple DWG files that were opened via ReadDwgFile(), you will need to assign each of them to different variables and be sure to dispose of each.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The best way to ensure that an object is disposed is with the using() statement. You can find plenty of examples of its use with Database and ReadDwgFile() if you search here and on the net.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2014 00:04:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/4768649#M63618</guid>
      <dc:creator>DiningPhilosopher</dc:creator>
      <dc:date>2014-01-23T00:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: ReadDwgFile eNotOpenForWrite</title>
      <link>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/5174683#M63619</link>
      <description>&lt;P&gt;I am trying to do saveAs from a file created from the most current version of autocad to 2010 version and i am getting a save error message of Warning: Error occured during save. We recommend that you run recover on the drawing.&lt;/P&gt;&lt;P&gt;here is my code&lt;BR /&gt;newDB.ReadDwgFile("C:\\MyDrawing\\Mass Haul-2_update2.dwg", FileOpenMode.OpenForReadAndAllShare, true, null);&lt;BR /&gt;newDB.SaveAs("C:\\MyDrawing\\Mass Haul-2_update22.dwg", DwgVersion.AC1024);&lt;/P&gt;&lt;P&gt;the new file would still be created though.&lt;/P&gt;&lt;P&gt;But if i open the original file and just do the saveas on the autocad menu , no errors encountered.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2014 21:50:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/readdwgfile-enotopenforwrite/m-p/5174683#M63619</guid>
      <dc:creator>mchan01</dc:creator>
      <dc:date>2014-07-24T21:50:36Z</dc:date>
    </item>
  </channel>
</rss>

