Visual Basic Customization

Visual Basic Customization

Reply
Active Member
Lynne
Posts: 6
Registered: ‎07-02-2004
Message 1 of 8 (93 Views)

Exporting text from AutoCAD to Excel

93 Views, 7 Replies
07-07-2004 03:23 AM
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?
*Matt W
Message 2 of 8 (93 Views)

Re: Exporting text from AutoCAD to Excel

07-07-2004 05:20 AM in reply to: Lynne
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?
*James Belshan
Message 3 of 8 (93 Views)

Re: Exporting text from AutoCAD to Excel

07-07-2004 06:27 AM in reply to: Lynne
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
*Matt W
Message 4 of 8 (93 Views)

Re: Exporting text from AutoCAD to Excel

07-07-2004 07:24 AM in reply to: Lynne
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. :smileyhappy: -- 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 | |
*Matt W
Message 5 of 8 (93 Views)

Re: Exporting text from AutoCAD to Excel

07-07-2004 07:39 AM in reply to: Lynne
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. :smileyhappy: | | -- | 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 | | | | | |
Active Member
Lynne
Posts: 6
Registered: ‎07-02-2004
Message 6 of 8 (93 Views)

Re: Exporting text from AutoCAD to Excel

07-21-2004 06:07 AM in reply to: Lynne
Thanks James and Matt for your assistance.
Could you help me to get the Autocad drawing name from autocad?
*MP
Message 7 of 8 (93 Views)

Re: Exporting text from AutoCAD to Excel

07-21-2004 06:32 AM in reply to: Lynne
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?
*Jürg Menzi
Message 8 of 8 (93 Views)

Re: Exporting text from AutoCAD to Excel

07-21-2004 06:39 AM in reply to: Lynne
Hi Lynne Thisdrawing.GetVariable("DWGNAME") Thisdrawing.GetVariable("DWGPREFIX") Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.