Data texts extraction from autocad

Data texts extraction from autocad

yasminezahir20
Contributor Contributor
979 Views
4 Replies
Message 1 of 5

Data texts extraction from autocad

yasminezahir20
Contributor
Contributor

Hi everyone I'm looking for a Data texts extraction from autocad to a an excel file using a command or VBA (here I mean by texts the texts that contain the objects informations) such as shown in this picture below.

 

0 Likes
980 Views
4 Replies
Replies (4)
Message 2 of 5

grobnik
Collaborator
Collaborator

Hi @yasminezahir20 just for example:

Sub Testi()
Dim oApp_Excel As Excel.Application
Dim oBook As Excel.workbook
Dim MyObject  As AcadEntity

Set oApp_Excel = CreateObject("EXCEL.APPLICATION")
Set oBook = oApp_Excel.workbooks.Add
oApp_Excel.Visible = True
oApp_Excel.workbooks(oApp_Excel.ActiveWorkbook.Name).Activate
Row = 2
For Each MyObject In ThisDrawing.ModelSpace
    If TypeOf MyObject Is AcadText Or TypeOf MyObject Is AcadMText Then
        If Right(MyObject.TextString, 2) <> "kW" Then 'Filter on partial text contents
            If Len(MyObject.TextString) > 1 Then 'filter on text with lenght higher than 1 char
                oApp_Excel.Sheets(ActiveSheet.Name).Range("A" & Row).Value = MyObject.TextString
                Row = Row + 1
            End If
        End If
    End If
Next
End Sub

 Please note that the above code extract all text, and Mtext including special format code of Mtext.

You should add to the project libray MS office Excel lib.

If you want to remove special code formatting from Mtext, search on this forum, there is a function for removing special char code.

Message 3 of 5

norman.yuan
Mentor
Mentor

It would be rather unlikely for you to find available VBA code that does exactly you want, while creating a more general-purpose data extraction code is not a trivial work. So, before you starts working on VBA code, or find/hire someone one do it for you, I hope you did tried AutoCAD's built-in data extract tool ( command "DataExtraction"), which is a general-purposed data extracting tool and quite flexible to use. You would only want re-invent a wheel for your specific road conditions when it is really necessary.

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 5

yasminezahir20
Contributor
Contributor
Thank you very much I'm working with Python (Pandas) now I find out a command for extracting data to a xls or csv file but now I'm trying to extract and filter data dirctly to my dataset from autocad.
0 Likes
Message 5 of 5

yasminezahir20
Contributor
Contributor
Thank you.
Yes exactly I tried the command dataextraction that gives me my data as csv or xls...file what I'm trying to do now it's to find out a way to extract and filter data dirctly to my dataset from autocad(that why I'm trying using VBA to add such command) and then I have to find out how to separate the line and text information from the recognized drawings then recognize the meaning of text in proximity to the shaped object on the drawing.
0 Likes