Jump to content

Reading text from specific text blocks


Recommended Posts

Posted

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

Posted

Is there a property to the text block that is unique?

Posted

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?

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

Posted

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.

Posted

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

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...