Reading DWG File with VB.NET without opening Autocad Editor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm rather new in .Net, though I want to make a Tool that will help me to analyze Used layers in a Folder with a lot of DWG's.
The subject is simple:
(For now)
Open File Dialogue Box, Select a DWG file, Read the DWG file to extract all layers to a text file.
(Later; read all DGW's of a slected Folder, read all the DWG's, export the layers and relative DWG to a TXT file, reading the txt file with another .Net application, entering a layer Keyword, get the DWG from the TXT file, open the DWG in True View.)
Here is my code for reading 1 DWG:
'***************************************************************************
Imports System.IO
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Public Class Form1
Private Sub SelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectFile.Click
Dim myStream As Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "D:\"
openFileDialog1.Filter = "DWG files (*.dwg)|*.dwg" openFileDialog1.FilterIndex = 1
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = openFileDialog1.OpenFile()
Finally
End Try
End If
If openFileDialog1.FileName.Length = 0 Then Exit Sub
Dim TextLine As String = Nothing
Dim objReader As New System.IO.StreamReader(myStream)
'Set path to DWGfile:
Dim myfile As String = Nothing
myfile = openFileDialog1.FileName
myfile = myfile.Replace(".dwg", ".txt")
'Delete Txt file if exists
Dim FileToDelete As String
FileToDelete = myfile
If System.IO.File.Exists(FileToDelete) = True Then System.IO.File.Delete(FileToDelete)
Dim objWriter As New System.IO.StreamWriter(myfile)
'Open the DWG File For Reading
Dim myDB As New DatabaseServices.Database
myDB.ReadDwgFile(openFileDialog1.FileName, FileOpenMode.OpenForReadAndAllShare, True)
Dim myBT As DatabaseServices.BlockTable = myDB.BlockTableId.GetObject(OpenMode.ForRead)
Dim myBTR As DatabaseServices.BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForRead)
For Each myObjID As ObjectId In myBTR
Dim myEntity As Entity = myObjID.GetObject(OpenMode.ForRead)
If myEntity.Layer.Length > 2 Then objWriter.Write(myEntity.Layer.Length)
Next
objWriter.Close()
myStream.Close()
MessageBox.Show("Writing succesful!", "Layer list", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
End Sub
End Class
'*********************************************************************
Copying this into VS 2008 does not give any Errors
The 2 necessary autocad dll's acdbmgd.dll and acmgd.dll are loaded and not copied.
Still when I want to run this code I receive the error:
Could not load assembly acdbmgd, Version=18.0.0.0, Culture=neutral, PublicKeyToken=null ...
Can anyone solve this problem? Which dll I have to add? Do I have to use other autocad dll ?
Thanx for reading this Subject.
Hope to receive an awnser.