Thank you! & TableExport VB Code

Discussion in 'AutoCAD' started by Dan, Aug 25, 2004.

  1. Dan

    Dan Guest

    I don't need anything.....currently.....But I wanted to say thank you to
    everyone. I am just starting out coding VB for AutoCAD/Excel/Word/Outlook
    and I greatly appreciate everyones willingness to help out and support. I
    hope one day, I will be able to assist others as well.

    Here is the TableExport code that James Belshan and (A HUGE thanks) Mike
    Tuersley basically wrote for me, and I implemented, and made a few
    modifications to add to my code. This was part of a HUGE application for me
    to start with that dealt with data throughout AutoCAD/Excel/Word/Outlook.

    Thanks again.
    Dan

    Sub TableExport()
    '------------------------------------------------My Dims Begin
    Dim thisdwgpath As String
    thisdwgpath = ThisDrawing.GetVariable("dwgprefix")
    Dim thisdwgname As String
    thisdwgname = ThisDrawing.GetVariable("dwgname")
    Dim thisnewdwgpath As String
    Dim thisnewdwgname As String
    Dim projectname As String
    'begin file new path loop
    i = 1
    For j = 1 To 3
    Do
    strA = Mid(thisdwgpath, i, 1)
    i = i + 1
    Loop Until strA = "\"
    Next j
    thisnewdwgpath = Left(thisdwgpath, i - 1)
    'end new file path loop
    'begin new file name loop
    i = 1
    Do
    strA = Mid(thisdwgname, i, 1)
    i = i + 1
    Loop Until strA = "."
    thisnewdwgname = Left(thisdwgname, i - 2)
    'end new file name loop
    'begin project name loop
    i = 1
    For j = 1 To 3
    Do
    strA = Mid(thisdwgpath, i, 1)
    i = i + 1
    Loop Until strA = "\": If j = 2 Then k = i
    Next j
    projectname = Mid(thisdwgpath, k, i - k - 1)
    'end project name loop

    '------------------------------------------------My Dims End
    Dim oTable As AcadTable
    Dim oSet As AcadSelectionSet
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Variant
    Dim cValue As Variant
    Dim lCols As Long
    Dim lRows As Long
    Dim cCntr As Long
    Dim rCntr As Long
    Dim sCSVFile As String
    Dim sRow As String
    Dim cValues As Collection
    Set cValues = New Collection
    FilterType(0) = 0
    FilterData(0) = "ACAD_TABLE"
    Set oSet = ThisDrawing.SelectionSets.Add("TableExporter")
    oSet.Select acSelectionSetAll, , , FilterType, FilterData
    Select Case oSet.Count
    Case Is = 0
    'MsgBox "No TABLES found!"
    Case Is = 1
    Set oTable = oSet(0)
    'get table's row & column counts
    lRows = oTable.Rows
    lCols = oTable.Columns
    'iterate the rows
    For rCntr = 0 To lRows - 1
    'iterate each column in row
    For cCntr = 0 To lCols - 1
    'read the row and pad it incase of a null value
    sRow = sRow & "" & oTable.GetText(rCntr, cCntr) & "|"
    Next
    'strip last pipe from string
    sRow = Mid(sRow, 1, Len(sRow) - 2)
    'add "row" to our collection
    cValues.Add sRow
    'reset the var for next pass
    sRow = vbNullString
    Next
    With ThisDrawing
    sCSVFile = .GetVariable("DWGNAME")
    sCSVFile = Replace(sCSVFile, ".dwg", ".csv")
    sCSVFile = .GetVariable("DWGPREFIX") & sCSVFile
    End With
    'write out lines of collection into file
    Open sCSVFile For Output As #1
    For Each cValue In cValues
    'need to substitute commas for pipe symbols here or earlier
    'need to wrap strings in quotes???
    Print #1, cValue
    'or could use write #1 to have quotes added automatically
    Next
    Close #1
    'clean up
    If Not oTable Is Nothing Then Set oTable = Nothing
    If Not oSet Is Nothing Then
    oSet.Delete
    Set oSet = Nothing
    End If
    Case Is > 1
    MsgBox "Too many TABLES found!"
    End Select
    End Sub
     
    Dan, Aug 25, 2004
    #1
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.