text in an Autocad drawing

Discussion in 'AutoCAD' started by Olivier, Dec 24, 2003.

  1. Olivier

    Olivier Guest

    Hello,

    I am writing a VB program to extract all the text from an Autocad drawing to
    put it in an excel spreadsheet.
    Could anybody tell me
    - what all the different places in theobject model are where one can find
    text
    - If there is an eays way to go through all hte objects in a drwaing, and if
    there are any watchouts.
    - If there are any code samples anywhere?

    thanks,
    Olivier
     
    Olivier, Dec 24, 2003
    #1
  2. Olivier

    bestafor Guest

    HiHo;
    Using a filter, (ssget "x" ((0 . "TEXT")))
    will create a selection set of all text.
    Step trough the selection set and extract all text entities
    and print to a *.txt file with a comma delimiter.
    Check out at www.cadalyst.com "get the code"
    for June 97 tip 1336 or Aug 01 tip 1730.
    Happy holidays.
     
    bestafor, Dec 24, 2003
    #2
  3. Olivier

    Paul Turvill Guest

    VB ... ?
    ___

     
    Paul Turvill, Dec 24, 2003
    #3
  4. Olivier

    Olivier Guest

    I am not sure what your message meant.
    If it means you do not know what VB stands for, it means Visual Basic.
    If it means you are surprised that I would use VB then, I would ask you why?


    Olivier
     
    Olivier, Dec 26, 2003
    #4
  5. Olivier

    Olivier Guest

    Do you have any idea how to do this in VB or VBA ?

    thnaks,

    Olivier
     
    Olivier, Dec 26, 2003
    #5
  6. Olivier

    Olivier Guest

    Do you have any idea how to do this in VB or VBA ?

    thnaks,

    Olivier
     
    Olivier, Dec 26, 2003
    #6
  7. Olivier

    Paul Turvill Guest

    My reply was to "bestafor," not to you. I was questioning "bestafor's"
    advice for solving your problem. You asked for a VB solution, and he offered
    you a LISP solution. Yes, I do know what VB stands for, but apparently
    "bestafor" missed that part of your request.
    ___
     
    Paul Turvill, Dec 26, 2003
    #7
  8. Olivier

    Jeff Guest

    Here are 2 functions to get you started. I've created a selection set of ALL
    text and Mtext in the drawing and placed the textstrings into an array that
    can be fed to Excel. See the sample excel link file in the Acad/Sample/VBA
    directory for help on that portion of the code.

    Option Explicit
    Private Function GetText() As Variant

    Dim aCod(0) As Integer, aVal(0) As Variant
    Dim oSet As AcadSelectionSet
    Dim iTmp As Integer
    Dim eEnt As AcadEntity
    Dim iCnt As Integer

    aCod(0) = 0: aVal(0) = "TEXT,MTEXT"
    Set oSet = SelSetInit("ssText")
    oSet.Select acSelectionSetAll, , , aCod, aVal
    iCnt = oSet.Count
    If iCnt > 0 Then
    ReDim vRet(1 To iCnt + 1) As String 'one added for header row
    vRet(1) = "Text Value"

    For iTmp = 0 To oSet.Count - 1
    Set eEnt = oSet.Item(iTmp)
    vRet(iTmp + 2) = eEnt.TextString
    Next
    Else
    MsgBox "No Text found!"
    End If

    Set eEnt = Nothing: Set oSet = Nothing
    GetText = vRet
    End Function

    Private Function SelSetInit(sName As String) As AcadSelectionSet
    Dim oRetVal As AcadSelectionSet
    On Error GoTo DeleteAndAdd
    Set oRetVal = ThisDrawing.SelectionSets.Add(sName)
    Set SelSetInit = oRetVal
    Exit Function
    DeleteAndAdd:
    ThisDrawing.SelectionSets.Item(sName).Delete
    Set oRetVal = ThisDrawing.SelectionSets.Add(sName)
    Set SelSetInit = oRetVal
    End Function

    HTH,
    Jeff
     
    Jeff, Dec 27, 2003
    #8
  9. Olivier

    Olivier Guest

    Jeff,

    thanks, this works great.
    Is there any text in an Autocad drawing besides Text and Mtext?

    thanks,

    Olivier
     
    Olivier, Dec 29, 2003
    #9
  10. Olivier

    Paul Turvill Guest

    One possibility: RText (Express Tools).
    ___
     
    Paul Turvill, Dec 29, 2003
    #10
  11. Olivier

    Paul Turvill Guest

    Oh ... and Attributes.
    ___
     
    Paul Turvill, Dec 29, 2003
    #11
  12. Olivier

    Jeff Guest

    And dimensions.....

    Jeff

     
    Jeff, Dec 29, 2003
    #12
  13. Olivier

    Olivier Guest

    Is there an easy way to modify the procedure you sent me to accomodat for
    attributes and dimensions?
    is it just a matter of changing the follwoing lien:

    aCod(0) = 0: aVal(0) = "TEXT,MTEXT"


    Thanks,

    Olivier
     
    Olivier, Dec 31, 2003
    #13
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.