PDA

View Full Version : Reading text from specific text blocks



tiger1337
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?

Thanks,
tiger1337

RMS
14th Jul 2010, 03:02 am
what are these drawings saved as .dwg or .dxf?

tiger1337
14th Jul 2010, 04:57 pm
They are saved as .dwg .

SEANT
14th Jul 2010, 09:50 pm
Is there a property to the text block that is unique?

tiger1337
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?

SEANT
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.

tiger1337
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
Exit For
End If
End If
Next

'store description lines
strD = varAttributes(3).TextString & " " _
& varAttributes(4).TextString & " " _
& varAttributes(5).TextString

'message box with description
MsgBox strD
End Sub


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.

tiger1337
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?

Thanks,
tiger1337

SEANT
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.

http://www.cadtutor.net/forum/showthread.php?26666

I suspect you will need to isolate the block associated with a Layout, then perform a search to return the BlockReference "BORDERA".

tiger1337
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?

~tiger1337