
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I'm trying to programmatically extra some data from a set of .DWG files. I've been trying to figure out how to do this using the ObjectArx 2010 .NET library against AutoCAD 2010.
I've been able to successfully extract the data from one file using some traversal logic based on a file that's read in starting with the following code:
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor '
Dim blockToFind As String = "(Name of a block I'm searching for)"
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
From there, I basically search for the named block, if it's found, I gather a collection of the different types of "columns", then search through each record and column combination to get the data I need.
It works exactly as I need when I do it in this manner except for one problem. For this method to work, the file I'm taking the data from has to be open in AutoCAD (as in File-->Open-->File name.dwg). Since I've got a large number of files to go through, I want to extract this data as part of a loop that traverses through a directory.
In order to do this, I tried to use .ReadDwgFile to access the file's contents. The code I'm using to initialize the file access is:
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = New Database(False, True)
Dim ed As Editor = doc.Editor
Dim fileName As String = "(Path to file)"
Try
db.ReadDwgFile(fileName, System.IO.FileShare.Read, False, "")
Catch ex As System.Exception
ed.WriteMessage(String.Format("{0}Unable to read drawing file. Exception Message: {1}", Environment.NewLine, ex.Message))
Return
End Try
'name of block to find
Dim blockToFind As String = "(Name of a block I'm searching for)"
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
In both cases, my logic starts with me getting a BlockTable object by using the document's database.BlockTableId. The name of the block I'm looking for is then used as an argument in a BlockTable.Has function. In the first set of code (when the document is manually opened in AutoCAD), the block I'm looking for is found. When the same function is used when the file is opened programmatically the .Has function returns nothing.
I notice when debugging that the size of the .ApproxNumObjects value when opening up the object using .ReadDwgFile is much, much larger than when the file is opened manually. What are some of the differences between these two access methods? Is there any clue as to why the .Has function returns nothing in the second case?
Solved! Go to Solution.