24 Posts
0 Kudos
Registered: ‎04-16-2011
Post 1 of 7

Reading data from autocad table

505 Views, 6 Replies
10-06-2011 04:48 AM

Greetings to all,


Here i have one question...

Is that possible to read the Autocad Table data , without opening the Autocad from VB.NET.


I tried with opening one autocad then loading the source dll. it was working perfectly.

but i need to without opening a application its possible or not?


Thanks in advance.


ADN Support Specialist
433 Posts
67 Kudos
Registered: ‎05-22-2006
Post 2 of 7

Re: Reading data from autocad table

10-06-2011 09:01 AM in reply to: ranjith0326

You could do this if you licensed RealDWG (www.autodesk.com/realdwg). But the public (free) AutoCAD APIs require you have AutoCAD installed on your computer (and running).


Stephen Preston
Autodesk Developer Network
*Expert Elite*
753 Posts
54 Kudos
Registered: ‎02-13-2008
Post 3 of 7

Re: Reading data from autocad table

10-06-2011 11:13 AM in reply to: ranjith0326

In addition to Stephens comment, you could use a COM application which would require you to open AutoCAD, but you could open it Invisibly, so the user doesn't see it open.  That's as close as you can get, without using RealDWG.

Dave O.                                                                  Sig-Logos32.png
24 Posts
0 Kudos
Registered: ‎04-16-2011
Post 4 of 7

Re: Reading data from autocad table

10-07-2011 12:49 AM in reply to: ranjith0326

Thank u so much,





242 Posts
16 Kudos
Registered: ‎12-15-2011
Post 5 of 7

Re: Reading data from autocad table

07-24-2012 10:56 PM in reply to: ranjith0326

Hey Ranjith, did you get any success in doing so. Because i am also looking for some similar kind of solution. Can you post it here if you have any

ADN Support Specialist
102 Posts
26 Kudos
Registered: ‎06-15-2011
Post 6 of 7

Re: Reading data from autocad table

08-01-2012 12:38 AM in reply to: amitk_189

Hi amit,


What kind of solution you are looking for? Can you please explain?


If you want to start AutoCAD from a external application using ActiveX API, then refer http://through-the-interface.typepad.com/through_the_interface/2007/12/launching-autoc.html & http://through-the-interface.typepad.com/through_the_interface/2010/02/handling-com-calls-rejected-b...

Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 7 of 7

Re: Reading data from autocad table

08-01-2012 03:52 AM in reply to: amitk_189

If you're still using COM, so try this code,

not tested seriously, just the same logic

as I'm posted before,

change file name you'll want to open


    Public Shared Sub ReadTableFromDwg()
        Dim acadver As String = "18" '//AutoCAD Version
        ' set your file name to read data here
        Dim fname As String = "C:\Test\mtext.dwg"
        ' define csv file name variable
        Dim csvname As String = String.Empty

        Dim listData As New List(Of Object)
        ' get current culture
        Dim oldCult As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
        ' create new culture
        Dim thisCult As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")
        ' set current culture to newly created
        System.Threading.Thread.CurrentThread.CurrentCulture = thisCult


        Dim appProgID As String = "Autocad.Application" + "." + acadver

        ' get reference on interface IDispatch
        Dim AcadType As Type = Type.GetTypeFromProgID(appProgID)

        ' launch AutoCAD
        Dim AcadApp As Object = Activator.CreateInstance(AcadType)

        Dim visargs() As Object = New Object(0) {}

        ' set visibility mode to false
        visargs(0) = True

        ' Make application visible
        AcadApp.GetType().InvokeMember("Visible", BindingFlags.SetProperty, Nothing, AcadApp, visargs, Nothing)

        ' Maximize window
        ''AcadApp.GetType().InvokeMember("WindowState", BindingFlags.SetProperty, Nothing, AcadApp, New Object() {1}, Nothing)

        Dim AcadDocs As Object = AcadApp.GetType().InvokeMember("Documents", BindingFlags.GetProperty, Nothing, AcadApp, Nothing)

        ' define arguments to open file
        Dim args() As Object = New Object(1) {}

        args(0) = fname
        ' set read only mode to false
        args(1) = False
        ' try open document
        Dim AcDoc As Object = AcadDocs.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, Nothing, AcadDocs, args, Nothing)

        Dim AcUtil As Object = New Object


            ' get reference on active document
            AcDoc = AcadApp.GetType().InvokeMember("ActiveDocument", BindingFlags.GetProperty, Nothing, AcadApp, Nothing, Nothing)
            ' get reference on ModelSpace
            Dim AcSpace As Object = AcDoc.GetType().InvokeMember("ModelSpace", BindingFlags.GetProperty, Nothing, AcDoc, Nothing)
            ' get reference of  AcadUtility
            AcUtil = AcDoc.GetType().InvokeMember("Utility", BindingFlags.GetProperty Or BindingFlags.Public, Nothing, AcDoc, Nothing)

            Dim acTable As New Object

            '        '_____________________________________________

            '        ' based on example written by Tony Tanzillo
            '        '_____________________________________________

            ' The array of arguments that will be passed
            ' to the AcadUtil.GetEntity() method:
            Dim entargs As Object() = New Object(2) {}

            ' In order to get VT_BYREF  arguments to be
            ' filled in by the callee, we must use ParameterModifier
            ' to retrieve the arguments:

            ' The callee will replace the ParameterModifier
            ' in the args[] argument array with the results.

            entargs(0) = New Object
            entargs(1) = New Object
            entargs(2) = vbLf + "! Select Table !"
            ' We also need to tell the marshaler that
            ' both parameters in the COM method call are
            ' 'out' or 'byref' parameters:
            ' 2 = the total number of arguments passed:
            Dim pm As New ParameterModifier(3)

            pm(0) = True
            ' first argument is ByRef
            pm(1) = True
            ' second argument is ByRef
            pm(1) = False
            ' third argument is ByVal
            Dim modifiers As ParameterModifier() = New ParameterModifier() {pm}

            ' Invoke the method, passing the arguments, and
            ' the parameter modifers

            AcUtil.GetType().InvokeMember("GetEntity", BindingFlags.InvokeMethod, Nothing, AcUtil, entargs, modifiers, Nothing, Nothing)

            ' The results are now in the entargs[] array:
            Dim entity As Object = DirectCast(entargs(0), Object)
            Dim pickpt As Object = DirectCast(entargs(1), Object)

            Dim objName As String = entity.GetType.InvokeMember("ObjectName", BindingFlags.GetProperty Or BindingFlags.IgnoreCase, Nothing, entity, Nothing).ToString()
            ' make sure the table object selected
            If objName <> "AcDbTable" Then

                MessageBox.Show("Selectet is not type of table, exit program ...")


            End If

            acTable = entity

            Dim tableRows As Object = acTable.GetType().InvokeMember("Rows", BindingFlags.GetProperty Or BindingFlags.Public, Nothing, acTable, Nothing)

            Dim tableColumns As Object = acTable.GetType().InvokeMember("Columns", BindingFlags.GetProperty Or BindingFlags.Public, Nothing, acTable, Nothing)

            Dim tableContent As New List(Of List(Of String))

            For i As Integer = 0 To tableRows - 1

                Dim tableLine As New List(Of String)

                For j As Integer = 0 To tableColumns - 1

                    Dim cellText As Object = acTable.GetType().InvokeMember("GetText", BindingFlags.InvokeMethod Or BindingFlags.Public, Nothing, acTable, New Object() {i, j})




            '' for debug only:

            'Dim sb As New StringBuilder
            'For Each line As List(Of String) In tableContent
            '    Dim textline As String = ""
            '    For Each st As String In line
            '        textline = textline + st + vbTab
            '    Next
            '    sb.AppendLine(textline.TrimEnd(vbTab))


            Dim initDir As String = AcDoc.GetType.InvokeMember("Path", BindingFlags.GetProperty, Nothing, AcDoc, Nothing, Nothing).ToString()

            Dim saveFileDialog As New System.Windows.Forms.SaveFileDialog

            saveFileDialog.Title = "Enter a file name to write data: "

            saveFileDialog.InitialDirectory = initDir

            saveFileDialog.RestoreDirectory = True

            saveFileDialog.Filter = "CSV files | *.csv"

            saveFileDialog.FileName = "File name without extension"

            Dim result As System.Windows.Forms.DialogResult = saveFileDialog.ShowDialog()

            If result <> DialogResult.OK Then
                csvname = "Not saved"
            End If

            csvname = saveFileDialog.FileName

            ' Write data to CSV
            Using sw As New StreamWriter(csvname, True, Encoding.ASCII)

                For Each line As List(Of String) In tableContent
                    Dim textline As String = ""
                    For Each st As String In line
                        textline = textline + st + vbTab
            End Using
            'save document
            Dim closeargs() As Object = New Object(1) {}
            closeargs(0) = True
            ' with the same name
            closeargs(1) = fname
            ' Try close document
            ' simplified syntax
            AcDoc.GetType().InvokeMember("Close", BindingFlags.InvokeMethod, Nothing, AcDoc, closeargs)

        Catch ex As System.Exception

            MessageBox.Show("Error: " & ex.Message & vbLf & "Trace: " & ex.StackTrace)


            ' Try quit application
            AcadApp.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, Nothing, AcadApp, Nothing)
            ' clean up the memory
            ' release Document.
            ' release Documents.
            ' release Application.
            ' call garbage cleaner immediatelly
            ' restore current culture
            System.Threading.Thread.CurrentThread.CurrentUICulture = oldCult
            'Display result
            MessageBox.Show("Csv file saved as:" + vbLf + csvname)
        End Try

    End Sub




Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!