Results 1 to 7 of 7

Thread: VB with Acad

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Malaysia
    Posts
    90
    Can I do a VB program to read an Acad R14 Dwg file then do a global search for some text string inside the dwg file. Would appreciate very much if someone from this forum can share their experience or suggest a good reference source on this subject.
    CT

  2. #2
    Junior Member
    Join Date
    Oct 2000
    Posts
    18
    It can be done. I have written thousands of lines of code to automate AutoCAD. Unfortunately, I have not done anything like this and therefore, don't have any sample code to post. Sorry!

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Yes, when you install AutoCAD it will put the appropriate ActiveX Controls/.dlls on your computer. While I don't have any code handy, the logic would be similar to this:

    set the reference in VB/VBA etc.
    create a AutoCAD object
    open the drawing
    loop through all items on paperspace or modelspace
    if they are an item that has text, manipulate them as desired
    close the drawing
    close AutoCad

    Hope that helps,
    Josh

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Malaysia
    Posts
    90
    Thanks guys! some samples posting should help to save many hours of hard works.

    Regards
    CT

  5. #5
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I had code that did pretty much what you want to do at one time, but I changed the specs to just deal with Blocks and rewrote the code, and I can't find a backup of the old code for you unfortunately.

    AutoCAD actually comes with decent help files for ActiveX/ VB, since you can use VBA within AutoCAD just like with MS Office Programs.

    Josh

  6. #6
    Junior Member
    Join Date
    Jul 2000
    Location
    Dublin
    Posts
    30
    CT,

    I've done what you are asking. I am a bit pushed for time at the moment so this is a bit rough. If you are still having problems contact me at my e-mail address.

    Make sure you have AutoCAD selected in the 'Project / Preferences' menu of VB.


    Dim acad As Object
    Dim doc As Object
    Dim mspace As Object
    Dim elem As Object

    ' Start AutoCAD
    Set acad = CreateObject("AutoCAD.Application")

    ' Make AutoCAD appear
    acad.Visible = True

    ' Define the current drawing as mspace
    Set doc = acad.ActiveDocument
    Set mspace = doc.ModelSpace

    ' Open a specific drawing
    doc.Open ("darwingname.dwg")


    For Each elem In mspace

    If (elem.EntityName = "AcDbText") Then

    If elem.TextString = "what ever you're looking or" then
    etc.
    etc.
    End If

    End if

    Next elem


    Good luck.

    Graham.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Malaysia
    Posts
    90
    Once again, many thanks to all that response to my question on the acad. Graham sample code should get me going for now. Will come back with more later.

    Kind regards
    CT

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width