VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Exporting text from AutoCAD to Excel

7 REPLIES 7
Reply
Message 1 of 8
l_guy
418 Views, 7 Replies

Exporting text from AutoCAD to Excel

I can only find a way of taking text from AutoCAD to Excel by picking on each piece of text, which is quite tedious.
Is their a way of getting visual basic to find the text by its co-ordinates?
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: l_guy

You can do something like this... Public Sub TextToExcel() Dim objText As AcadText For Each objText In ThisDrawing.ModelSpace ' Insert code to export to Excel here... Next objText End Sub If you need more help, let me know... -- Matt W The difference between genius and stupidity is that genius has its limits. "Lynne" wrote in message news:14275464.1089195863740.JavaMail.jive@jiveforum2.autodesk.com... | I can only find a way of taking text from AutoCAD to Excel by picking on each piece of text, which is quite tedious. | Is their a way of getting visual basic to find the text by its co-ordinates?
Message 3 of 8
Anonymous
in reply to: l_guy

Matt, Your code would crash if there were any non-text items in modelspace. It needs to be something more like: dim objEnt as AcadEntity > Dim objText As AcadText > > For Each objEnt In ThisDrawing.ModelSpace If TypeOf objEnt is AcadText Then Set objText = objEnt > ' Insert code to export to Excel here... EndIf > Next objEnt Lynne, You could use the SelectOnScreen method, with a filter on so that only text items are selected, to get all the text in an area. Or, to use Matt's code, you would check the .InsertionPoint of each Text item to see if it's the one(s) you want. HTH, James
Message 4 of 8
Anonymous
in reply to: l_guy

Yeah, you're right. I just threw something together really quick, which is why it worked on a BLANK drawing with only 3 pieces of text. :) -- Matt W The difference between genius and stupidity is that genius has its limits. "James Belshan" wrote in message news:40ebfa79$1_3@newsprd01... | Matt, | Your code would crash if there were any non-text items in modelspace. It | needs to be something more like: | | dim objEnt as AcadEntity | > Dim objText As AcadText | > | > For Each objEnt In ThisDrawing.ModelSpace | If TypeOf objEnt is AcadText Then | Set objText = objEnt | > ' Insert code to export to Excel here... | EndIf | > Next objEnt | | Lynne, | You could use the SelectOnScreen method, with a filter on so that only text | items are selected, to get all the text in an area. Or, to use Matt's code, | you would check the .InsertionPoint of each Text item to see if it's the | one(s) you want. | | | HTH, | James | |
Message 5 of 8
Anonymous
in reply to: l_guy

Lynne: You can use this to import text from AutoCAD to Excel as well as the coordinates... You'll just have to add a reference to Excel in the VBA IDE. [code] Option Explicit Public intRow As Integer Public strCell As String ' Application - Excel Public oExcel As Excel.Application Public oBook As Excel.Workbook Public oSheet As Excel.Worksheet Private Sub CreateExcel() Dim i As Integer Set oExcel = CreateObject("Excel.Application") Set oBook = oExcel.Workbooks.Add Set oSheet = oBook.Worksheets(1) oExcel.Visible = True End Sub Public Sub TextToExcel() Dim obj As AcadEntity Dim objText As AcadText Dim varInsert As Variant ' Create an Excel object CreateExcel oExcel.Cells(1, 1).Value = "TEXT" oExcel.Cells(1, 2).Value = "X: COORDINATE" oExcel.Cells(1, 3).Value = "Y: COORDINATE" oExcel.Cells(1, 4).Value = "Z: COORDINATE" intRow = 2 For Each obj In ThisDrawing.ModelSpace If TypeOf obj Is AcadText Then Set objText = obj oExcel.Cells(intRow, 1).Value = objText.TextString varInsert = objText.InsertionPoint oExcel.Cells(intRow, 2).Value = varInsert(0) oExcel.Cells(intRow, 3).Value = varInsert(1) oExcel.Cells(intRow, 4).Value = varInsert(2) intRow = intRow + 1 End If Next obj End Sub [/code] -- Matt W The difference between genius and stupidity is that genius has its limits. "Matt W" wrote in message news:40ec07f4$1_3@newsprd01... | Yeah, you're right. | I just threw something together really quick, which is why it worked on a | BLANK drawing with only 3 pieces of text. :) | | -- | Matt W | | The difference between genius and stupidity is that genius has its limits. | "James Belshan" wrote in message | news:40ebfa79$1_3@newsprd01... | | Matt, | | Your code would crash if there were any non-text items in modelspace. It | | needs to be something more like: | | | | dim objEnt as AcadEntity | | > Dim objText As AcadText | | > | | > For Each objEnt In ThisDrawing.ModelSpace | | If TypeOf objEnt is AcadText Then | | Set objText = objEnt | | > ' Insert code to export to Excel here... | | EndIf | | > Next objEnt | | | | Lynne, | | You could use the SelectOnScreen method, with a filter on so that only | text | | items are selected, to get all the text in an area. Or, to use Matt's | code, | | you would check the .InsertionPoint of each Text item to see if it's the | | one(s) you want. | | | | | | HTH, | | James | | | | | |
Message 6 of 8
l_guy
in reply to: l_guy

Thanks James and Matt for your assistance.
Could you help me to get the Autocad drawing name from autocad?
Message 7 of 8
Anonymous
in reply to: l_guy

system variable "Dwgname", also of interest "Dwgprefix" ??? "Lynne" wrote in message news:27743389.1090415294290.JavaMail.jive@jiveforum2.autodesk.com... > Thanks James and Matt for your assistance. > Could you help me to get the Autocad drawing name from autocad?
Message 8 of 8
Anonymous
in reply to: l_guy

Hi Lynne Thisdrawing.GetVariable("DWGNAME") Thisdrawing.GetVariable("DWGPREFIX") Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost