+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Full Member CaveMan's Avatar
    Computer Details
    CaveMan's Computer Details
    Operating System:
    XP - Win7 32 & 64
    Computer:
    64Bit Hybrid
    CPU:
    Intel i7
    RAM:
    12 Gig
    Graphics:
    GeForce GT 220
    Monitor:
    Dual Dell 22"
    Using
    AutoCAD 2011
    Join Date
    Jul 2011
    Location
    South Africa - JHB
    Posts
    41

    Default AutoCAD Tables Data Extraction

    Good Day

    looking for assistance with extracting data from an AutoCAD table.
    Hav found a fex examples on how to create a table in AutoCAD with VB.Net but no luck on how to loop through the rows and columns in an AutoCAD table and see the items within. Want to be able to loop through a list of drawings, open drawings find the table in Paper or Model space, loop through the records and export them to excel - SQL or XML, or even a simple method of creating a collection if records in VB.Net, where one colud then export the list

    Any assistnace most welcome
    Regards

  2. #2
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,687

    Default

    Give this a try, change full path of folder and CSV file name
    at the start of command WTB

    Code:
     
    Imports System
    Imports System.Text
    Imports System.IO
    Imports System.Data
    Imports System.Linq
    Imports Autodesk.AutoCAD.Runtime
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.EditorInput
    Imports Autodesk.AutoCAD.Geometry
    Imports Autodesk.AutoCAD.ApplicationServices
     
    ''-----------------------------------------''
     
            Public Function GetDirectoryDrawings(directoryFullName As String, subDirsBrowse As Boolean) As List(Of FileInfo)
                Dim dir As New DirectoryInfo(directoryFullName)
                If Not dir.Exists Then
                    Throw New DirectoryNotFoundException()
                    Return Nothing
                End If
                Dim opt As SearchOption = SearchOption.AllDirectories
                If subDirsBrowse = False Then opt = SearchOption.TopDirectoryOnly
                Return dir.GetFiles("*dwg", opt).AsEnumerable().OrderBy(Function(x) x.FullName).ToList()
            End Function
            'change command name to suit
            <CommandMethod("wtb", CommandFlags.Session)> _
            Public Sub testDirFiles()
                Dim folder As String = "C:\Test\"
                Dim csvfile As String = "C:\Test\atable.csv"
                Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
                Dim db As Database = doc.Database
                Dim ed As Editor = doc.Editor
                Dim fd As List(Of FileInfo) = GetDirectoryDrawings(folder, False) ''     True for processing the subdirectories
                Dim collect As New StringBuilder
                If fd.Count = 0 Then Return
     
                Try
                    Using doclock As DocumentLock = doc.LockDocument()
                        For n As Integer = 0 To fd.Count - 1
                            Dim dwgname As String = fd(n).FullName
                            Using newdb As Database = New Database(False, True)
                                ed.WriteMessage(vbLf + dwgname + vbLf)
                                Try
                                    newdb.ReadDwgFile(dwgname, FileOpenMode.OpenForReadAndAllShare, False, Nothing)
                                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                                    If ex.ErrorStatus = ErrorStatus.DwgNeedsRecovery Then
                                        Continue For
                                    End If
                                End Try
     
                                Using newtr As Transaction = newdb.TransactionManager.StartTransaction
                                    ' Open dictionary for reading 
                                    Dim layoutDict As DBDictionary = DirectCast(newtr.GetObject(newdb.LayoutDictionaryId, OpenMode.ForRead), DBDictionary)
                                    ' Loop through dictionary entries
                                    For Each entry As DictionaryEntry In layoutDict
                                        Dim ltr As Layout = DirectCast(newtr.GetObject(DirectCast(entry.Value, ObjectId), OpenMode.ForRead), Layout)
                                        Dim btr As BlockTableRecord = DirectCast(newtr.GetObject(ltr.BlockTableRecordId, OpenMode.ForRead), BlockTableRecord)
                                        For Each id As ObjectId In btr
                                            Dim obj As DBObject = DirectCast(newtr.GetObject(id, OpenMode.ForRead), DBObject)
                                            If TypeOf obj Is Table Then
                                                Dim tbl As Table = TryCast(obj, Table)
                                                If tbl IsNot Nothing Then
                                                    collect.AppendLine(String.Format("---------------------------------------"))
                                                    collect.AppendLine(String.Format("Drawing name: {0}", dwgname))
                                                    collect.AppendLine(String.Format("Tab: {0}", ltr.LayoutName))
                                                    Dim numrows As Integer = tbl.Rows.Count
                                                    Dim numcols As Integer = tbl.Columns.Count
                                                    For i As Integer = 0 To numrows - 1
                                                        Dim rowline As New List(Of String)
                                                        Dim line As String = String.Empty
                                                        For j = 0 To numcols - 1
                                                            Dim cel As Cell = tbl.Cells(i, j)
                                                            rowline.Add(cel.TextString)
                                                            line = line + cel.TextString + vbTab
                                                        Next
                                                        collect.AppendLine(line.TrimEnd(vbTab))
                                                    Next
                                                End If
                                            End If
                                        Next
                                    Next
                                    newtr.Commit()
                                End Using
                            End Using
                        Next
                    End Using
                    WriteTableToFile(csvfile, collect)
                Catch ex As System.Exception
                    ed.WriteMessage(vbLf + ex.ToString + vbLf)
                Finally
                    ed.WriteMessage(vbLf + vbTab + "--->   File saved as: {0}   <---" + vbLf, csvfile)
                End Try
            End Sub
     
            Public Sub WriteTableToFile(fpath As String, data As StringBuilder)
     
                Using fs As New FileStream(fpath, FileMode.Append, FileAccess.Write)
                    Using sw As New StreamWriter(fs, Encoding.ASCII)
                        sw.WriteLine(data.ToString)
                    End Using
                End Using
            End Sub
    ~'J'~

    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  3. #3
    Full Member CaveMan's Avatar
    Computer Details
    CaveMan's Computer Details
    Operating System:
    XP - Win7 32 & 64
    Computer:
    64Bit Hybrid
    CPU:
    Intel i7
    RAM:
    12 Gig
    Graphics:
    GeForce GT 220
    Monitor:
    Dual Dell 22"
    Using
    AutoCAD 2011
    Join Date
    Jul 2011
    Location
    South Africa - JHB
    Posts
    41

    Default

    Good Day

    Been a while since i have done some development, as always much appreciate your assistance and example code . . .
    Will work through your example code, Will let you know if success.

    Best Regards Richard
    Keep Well

  4. #4
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,687

    Default

    Thanks bro,
    Let me know if some issues is appears,

    ~'J'~
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  5. #5
    Forum Newbie
    Using
    AutoCAD 2012
    Join Date
    Aug 2013
    Posts
    1

    Default DataExtract option question

    Hello "fixo",
    Would you please answer this question:
    Would DATAEXTRACT work with old Drawings prior to design of 2002 AutoCAD as well as the 2012 and later on?

    Would the data extract on drawing be consistent in Column count for every drawing? or does it very from drawing to drawing?

    I also try to add the VB code to a project and it can not find the names spaces mentioned in the import.


    Am I doing something wrong? I have AutoCAD 2012 installed.


    Thank you.

  6. #6
    Full Member CaveMan's Avatar
    Computer Details
    CaveMan's Computer Details
    Operating System:
    XP - Win7 32 & 64
    Computer:
    64Bit Hybrid
    CPU:
    Intel i7
    RAM:
    12 Gig
    Graphics:
    GeForce GT 220
    Monitor:
    Dual Dell 22"
    Using
    AutoCAD 2011
    Join Date
    Jul 2011
    Location
    South Africa - JHB
    Posts
    41

    Default DataExtract

    Registered forum members do not see this ad.

    Hi There

    The sample code that was given was VB.NET version 3.5
    AutoCAD 2012 was upgraded to .Net 4

    The Name Spaces were changed between .Net 3.5 and .Net 4
    Regrets i have never upgraded the code to work on .Net 4

    To be able to compile and edit the code, you can use VS 2010

    Link Provided Below

    http://www.microsoft.com/visualstudi...d-2010-express

    The setup and environment would also require a bit of understanding in Developing .Net add ons for AutoCAD. Link provided below

    http://usa.autodesk.com/adsk/servlet...112&id=1911627

    The Data below will search for all Tables then loop through all the columns then rows for the particular table, if you had 10 various table in a drawing, it will extract all the data specific to each table, no matter how different they are.

    I say this under correction, but if you open a previous version of AutoCAD with tables in it and AutoDesk have not changed their table class then the data should be able to be extracted. If you look at the Properties of the object in AutoCAD as the attached image this must be Table.

    Table.png

    I have however seen other table types in AutoCAD, Like AutoCAD Structural Detailing, but have never tried to check or extract the data from them.

    Hope that the above information provides some help, If i ever get some time i will update the Data Extract function and attach a zip file with a .Net Compiled Project. Sadly i am renovating my house this side and not much time available.

    Best Regards
    Richard

Similar Threads

  1. Data extraction tables: Extremely tantalizing but entirely useless?
    By WINTERMUTE in forum AutoCAD Drawing Management & Output
    Replies: 15
    Last Post: 1st Jun 2012, 09:10 pm
  2. Help with data extraction tables and fields
    By Catgirl in forum AutoCAD Beginners' Area
    Replies: 1
    Last Post: 14th Jun 2011, 03:01 am
  3. Data Extraction Tables
    By leemckenzie in forum AutoCAD General
    Replies: 0
    Last Post: 19th Jul 2010, 12:42 am
  4. Autocad 2010 Data Extraction
    By WCCSAM in forum AutoCAD Drawing Management & Output
    Replies: 0
    Last Post: 20th May 2010, 08:31 pm
  5. Tables from Datalinking and Data Extraction in AutoCAD 2008
    By AutoCAD Insider in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 22nd Feb 2007, 04:50 pm

Tags for this Thread

Bookmarks

Posting Permissions

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