View Full Version : Reading text from specific text blocks
13th Jul 2010, 11:04 pm
hello all, I'm just starting to write scripts for autocad in vba. I just finished one that re-numbers all the line numbers I select on my drawing. Now, I would like to write a program that automates the process of making a table of contents. Basically the only input will need to be a folder location with drawings, each drawing having an identical text block of header information, and the program will then open all files, extract information from the description block, and then put it into a table. My question is: how do I access text from a text block without having a user need to select it?
14th Jul 2010, 03:02 am
what are these drawings saved as .dwg or .dxf?
14th Jul 2010, 04:57 pm
They are saved as .dwg .
14th Jul 2010, 09:50 pm
Is there a property to the text block that is unique?
15th Jul 2010, 02:02 am
Well, it's unique in that it is the only text block on any of the drawings. (All other text appears in single line text boxes.) The header text block in question is one which I double click to explode and edit each field individually. Is this what you mean?
15th Jul 2010, 09:48 am
Well, it's unique in that it is the only text block on any of the drawings. (All other text appears in single line text boxes.)
By that do you mean it is the only MTEXT in the drawing; any other text would be the single line TEXT entity?
The header text block in question is one which I double click to explode and edit each field individually. Is this what you mean?
This line sounds like you’re dealing with a block. Is it possible to post an example? It would certainly allow more informed advise.
Either scenario would allow a program the opportunity to isolate and modify accordingly. ObjectDBX (there are several threads in the forum) would be a good choice to examine the database of a group of drawings without having to open them in the drawing editor.
19th Jul 2010, 07:25 pm
Ok, sorry for the long delay since the last post.
As of right now, I can't post a sample .dwg file, but I have made some progress on the program itself. Hopefully this will give everyone a clear idea of what I am doing:
Public Sub GetDescription()
Dim varAttributes As Variant
Dim objTemp As Object
Dim strD As String
'loop through each block until the specific one is found
For Each objTemp In ThisDrawing.ActiveLayout.Block
If objTemp.EntityName = "AcDbBlockReference" Then
If objTemp.Name = "BORDERA" Then
'varAttributes now has attributes of specific block
varAttributes = objTemp.GetAttributes
'store description lines
strD = varAttributes(3).TextString & " " _
& varAttributes(4).TextString & " " _
'message box with description
To sum what you see here, basically this script finds the block titled "BORDERA", and saves the values it finds in the 4th, 5th, and 6th attribute. (I have a three line description on every drawing.) Right now I am taking baby steps to get this project working. The next task will be to open all drawings in a specified folder and get the description for every drawing. I will look into your suggestion, SEANT, about using objectDBX.
I'll post my progress as I go, but any further suggestions about the project is appreciated.
19th Jul 2010, 08:51 pm
ok, so I've been looking up how to use objectDBX for quite some time now and I can't figure out how to start. The way I see it, once I open each file in a forloop, I should be able to apply my previous script to access the description lines. Can someone help me with the syntax for this?
20th Jul 2010, 09:37 am
The "ThisDrawing.ActiveLayout" object is not available with ObjectDBX. Nor, for that matter, is "ThisDrawing". Look at the code examples in this thread to see a way of isolating a particular Block.
I suspect you will need to isolate the block associated with a Layout, then perform a search to return the BlockReference "BORDERA".
20th Jul 2010, 03:51 pm
ok so I'm making progress with the objectDBX. Below is a snippet of how I am using it:
Dim dbxDoc As AXDBLib.AxDbDocument
Set dbxDoc = Application.GetInterfaceObject("ObjectDBX.AxDbDocument.17")
dbxDoc.Open (strPath & "\" & strList(intJ))
Set dbxDoc = Nothing
I'm wondering if that last line of code is properly closing the file. I'm still unfamiliar with all the syntax and I know properly closing files in programs is important. The code above will be in a for loop (aside from the dim statement). Will the last line of code close the file? Or is this not even necessary for objectDBX?
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.