<?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: opening DWG files not produced from an Autodesk product in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887574#M62204</link>
    <description>&lt;P&gt;db.ReadDwgFile(FileName, System.IO.FileShare.Read, True, "")&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jan 2011 16:13:46 GMT</pubDate>
    <dc:creator>arcticad</dc:creator>
    <dc:date>2011-01-20T16:13:46Z</dc:date>
    <item>
      <title>opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2886940#M62198</link>
      <description>&lt;P&gt;I have some DWG files that I can not get to open with the following code to process them as some batch operation, these files were exported from Solid Works and are not real DWG files. can I open them in some other way to get simple batch operations to work with non Autodesk DWG files?&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("Batch")&amp;gt; Public Sub bathcfiles()
        Dim acDialog As New System.Windows.Forms.OpenFileDialog
        acDialog.Multiselect = True
        If acDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then
            For Each i As String In acDialog.FileNames
                Dim acDocMgr As DocumentCollection = Application.DocumentManager
                Dim acDoc As Document = acDocMgr.Open(i, True)
                ' do something with the file

                acDoc.CloseAndDiscard()
            Next
        End If
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2011 03:46:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2886940#M62198</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2011-01-20T03:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887094#M62199</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/506518"&gt;@Mike.Wohletz&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;I have some DWG files that I can not get to open with the following code to process them as some batch operation, these files were exported from Solid Works and are not real DWG files. can I open them in some other way to get simple batch operations to work with non Autodesk DWG files?&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("Batch")&amp;gt; Public Sub bathcfiles()
        Dim acDialog As New System.Windows.Forms.OpenFileDialog
        acDialog.Multiselect = True
        If acDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then
            For Each i As String In acDialog.FileNames
                Dim acDocMgr As DocumentCollection = Application.DocumentManager
                Dim acDoc As Document = acDocMgr.Open(i, True)
                ' do something with the file

                acDoc.CloseAndDiscard()
            Next
        End If
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you include a msgbox so as to view the path of the file you want to open because i'm not sure the opendialogfille reply the complete path.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bye&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2011 10:01:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887094#M62199</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-01-20T10:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887152#M62200</link>
      <description>&lt;P&gt;Try to change value of DWGCHECK system variable before opening dwg.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2011 11:37:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887152#M62200</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-01-20T11:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887292#M62201</link>
      <description>&lt;P&gt;DWGCHECK is set to 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works fine on all normal DWG files created by an Autodesk application, the problem that I have is if one of these gets into the mix of my batch it will crash the application and will go no farther.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2011 13:43:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887292#M62201</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2011-01-20T13:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887368#M62202</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Imports Autodesk.AutoCAD.DatabaseServices

Public Class resave

    Sub testit()
        ' resave the drawing before opening it in Autocad Interface. 
        ReSaveFile("c:\test1.dwg")
    End Sub

    Function ReSaveFile(ByVal FileName As String) As Boolean
        If FileExists(FileName) Then
            If Not isFileInUse(FileName) Then
                Using db As New Database(False, False)
                    Try
                        ' Read File 
                        db.ReadDwgFile(FileName, FileOpenMode.OpenForReadAndReadShare, True, "")
                        ' Write File
                        db.SaveAs(FileName, True, DwgVersion.Current, db.SecurityParameters)
                        Return True
                    Catch ex As System.Exception
                        Return False
                    End Try
                End Using
            Else
                Return False
            End If
        Else
            Return False
        End If

    End Function

    Public Function FileExists(ByVal FileFullPath As String) _
   As Boolean
        Try
            Dim f As New IO.FileInfo(FileFullPath)
            Return f.Exists
        Catch ex As Exception
            Return False
        End Try

    End Function

    Public Function isFileInUse(ByVal sFile As String) As Boolean

        If System.IO.File.Exists(sFile) Then
            Try
                Dim F As Short = CShort(FreeFile())
                FileOpen(F, sFile, Microsoft.VisualBasic.OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
                FileClose(F)
            Catch
                Return True
            End Try
        End If
    End Function
End Class&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2011 14:27:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887368#M62202</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2011-01-20T14:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887422#M62203</link>
      <description>&lt;P&gt;&lt;FONT size="2"&gt;I am a bit lost, tried all sorts of commandflags and still nothing. Tried the resave options and it craps out at &lt;/FONT&gt;&lt;FONT size="1"&gt;"&lt;/FONT&gt;&lt;FONT size="1"&gt;db.ReadDwgFile(FileName, FileOpenMode.OpenForReadAndReadShare, &lt;/FONT&gt;&lt;FONT size="1"&gt;&lt;FONT color="#0000ff"&gt;&lt;FONT color="#0000ff"&gt;True&lt;/FONT&gt;&lt;/FONT&gt;, &lt;FONT color="#a31515"&gt;&lt;FONT color="#a31515"&gt;""&lt;/FONT&gt;&lt;/FONT&gt;)" &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;the error is "eNoInputFiler"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I have attached a sample drawing with this, this drawing has had all the proprietary information removed and resaved as an AutoCAD Mechanical 2008 file. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;this is a screenshot of my debug window.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forums.autodesk.com/t5/image/serverpage/image-id/3214iD3A6CF11C18C6E4A/image-size/original?v=mpbl-1&amp;amp;px=-1" title="Acad App" align="center" alt="Acad App" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2011 15:04:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887422#M62203</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2011-01-20T15:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887574#M62204</link>
      <description>&lt;P&gt;db.ReadDwgFile(FileName, System.IO.FileShare.Read, True, "")&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2011 16:13:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887574#M62204</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2011-01-20T16:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887780#M62205</link>
      <description>&lt;P&gt;&lt;IMG src="http://forums.autodesk.com/t5/image/serverpage/image-id/3222i3EF74B3CC782F584/image-size/original?v=mpbl-1&amp;amp;px=-1" title="AcadApp capture2.JPG" align="center" alt="AcadApp capture2.JPG" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2011 17:59:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887780#M62205</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2011-01-20T17:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887904#M62206</link>
      <description>&lt;P&gt;You need to lock the document first&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;      &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Using lock As DocumentLock = dwg.LockDocument&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Using db As New Database(False, False) &amp;nbsp;&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; ....&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Using&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Using&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2011 19:13:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2887904#M62206</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2011-01-20T19:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2888422#M62207</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you need to set DWGCHECK system variable to 2 first. And if you need to take some action depending if the dwg is a trusted one, you can check the &lt;SPAN style="color: #660000;"&gt;&lt;STRONG&gt;DwgFileWasSavedByAutodeskSoftware&lt;/STRONG&gt; &lt;FONT color="#000000"&gt;of the database object.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #660000;"&gt;&lt;FONT color="#000000"&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #660000;"&gt;&lt;FONT color="#000000"&gt;Gaston Nunez&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2011 00:38:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2888422#M62207</guid>
      <dc:creator>hgasty1001</dc:creator>
      <dc:date>2011-01-21T00:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: opening DWG files not produced from an Autodesk product</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2888944#M62208</link>
      <description>&lt;P&gt;Thanks that solved the problem, my first issue was not being able to open the files in a batch and the DWGCHECK set to 2 solved that. This will allow me to batch plot or some other routine that will not make changes to the file. the second is the DwgFileWasSavedByAutodeskSoftware will solve the problem of modifying drawing, if I hit this and it is false I know that it was not done in AutoCAD and can move on to the next.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My testing code that is working:&lt;/P&gt;&lt;PRE&gt;Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices


Public Class Class1
    &amp;lt;CommandMethod("Batch", CommandFlags.Session)&amp;gt; Public Sub bathcfiles()
        Dim acDialog As New System.Windows.Forms.OpenFileDialog
        acDialog.Multiselect = True
        acDialog.Filter = "Drawing Files (*.DWG)|*.DWG"
        Dim acDwgCheck As Integer = Application.GetSystemVariable("DWGCHECK")
        Application.SetSystemVariable("DWGCHECK", 2)
        Try
            If acDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then
                For Each i As String In acDialog.FileNames
                    Dim acDocMgr As DocumentCollection = Application.DocumentManager
                    Dim acDoc As Document = acDocMgr.Open(i)
                    ' do something with the file
                    If acDoc.Database.DwgFileWasSavedByAutodeskSoftware Then
                        ' this is an Autodesk DWG so we can make changes
                        MsgBox(String.Format("file: {0} was created by an Autodesk application", acDoc.Name))
                    Else
                        MsgBox(String.Format("file: {0} was not created by an Autodesk application", acDoc.Name))
                    End If
                    acDoc.CloseAndDiscard()
                Next
            End If
        Catch ex As Autodesk.AutoCAD.Runtime.Exception
            MsgBox(ex.Message)
        End Try
        Application.SetSystemVariable("DWGCHECK", acDwgCheck)
    End Sub
  
End Class&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2011 14:24:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-dwg-files-not-produced-from-an-autodesk-product/m-p/2888944#M62208</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2011-01-21T14:24:50Z</dc:date>
    </item>
  </channel>
</rss>

