Consulting

Page 3 of 3 FirstFirst 1 2 3
Results 41 to 53 of 53

Thread: Solved: VBA and AutoCAD reading points from a txt file?

  1. #41
    Tommy,

    Here is the latest problem/BUG, working with the new code but this BUG happens with the old code as well, maybe its me/my config files, I am not sure. I have both txt files up to frame 25, but I only get approx 16 or 18 frames, and a debug error; see pic. What do you think is the problem?
    Last edited by Zrob; 04-14-2008 at 09:19 AM.
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  2. #42
    Ok I found it, a double entry in my config file......lets see if I can get past 25 frames now......
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  3. #43
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    What no text files? LOL I have up to 18 frames and it look really good.

  4. #44
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    btw before I forget; the safe array complaint from acad means that the program has reached the end of the information.

  5. #45
    Well I call my txt files config......

    Tommy, I was thinking to bad we could not tag each frame to a matching layer....that would be slick!
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  6. #46
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    [VBA]
    Sub AddLayer(iFrameNo As Long)
    Dim mLayer As AcadLayer
    'copied straight from the help files
    Set mLayer = ThisDrawing.Layers.Add(CStr(iFrameNo))
    mLayer.Linetype = "CONTINUOUS"
    mLayer.Color = iFrameNo
    ThisDrawing.ActiveLayer = mLayer
    'now draw
    End Sub
    Sub ReadFileIntoArray()
    .......
    If mStr > 0 Then
    SortaPoint FramArray
    AddLayer mFrmNo
    Set mPoly = ThisDrawing.ModelSpace.Add3DPoly(FramArray)
    End If
    ........
    End Sub

    [/VBA]


  7. #47
    Tommy, I added Foc'sle Deck data, though a small problem with the line directions at the top, not sure what you think, but I will try and run that data by itself, then see what it does.

    Thanks!
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  8. #48
    Ok, so I went to the last saved data files without the Foc'sle dat and ran that, then I ran just the Foc'sle data and here is what I got. I am sure you can figure this one out.......I need to think about it for now. But I think I can work arround it. I think I will run one more combination hang on.....
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  9. #49
    Ok I ran the data once wth the Foc'sle data inbeded then once with just the Foc'sle data. Not sure.......but this kida seem like the right profile. Though I will have to check the CAD file better.

    What do you make of it?
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  10. #50
    This is up to frame 59 with the new layer code. NICE!
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  11. #51
    This is the first step, finished. Next will be to clean things up, and put some surfaces on and I may do that in another cad package.
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  12. #52
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    can i like to export autocad (dwg) date to excel.. like dimesions,drawing no..etc..do help me soooon

  13. #53

    this code does'nt work for me...

    hi tommy,
    why this code not work when i try to run in autocad?
    it says run time erro 99
    subscript out of range

    ive change the path of a txt file.."D:\coordinates.txt"

    what will i do? i need this macro that autocad will import txt file coordinates and plot a line in autocad.. anybody can answer this please... thanks in advance

    Option Explicit
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    Public Function ReadTxtFile(fil As String) As Collection
    Dim fd As Long
    Dim sline As String
    Dim txtColl As New Collection
    fd = FreeFile
    Open fil For Input Access Read Shared As fd
    Do Until EOF(fd)
    Line Input #fd, sline
    txtColl.Add sline
    Loop
    Close fd
    Set ReadTxtFile = txtColl
    End Function

    '~~~~~~~~~~~~~~~~~~~~~~~~~~~'

    Sub test()
    Dim col As New Collection
    Dim itm As Variant
    Dim ar() As Variant
    Dim i As Integer, j As Integer
    Dim iCount As Integer
    Set col = ReadTxtFile("C:\Temp\Frame_Profiles.txt") '<-change the full path of the text file
    For i = 1 To col.Count Step 2
    ReDim Preserve ar(j)
    ar(j) = col.Item(i) & col.Item(i + 1)
    j = j + 1
    Next
    iCount = UBound(ar)
    Dim match As String
    Dim framenum As String
    i = 0
    Do Until i >= iCount
    j = 0
    DoNext:
    Dim pts() As Double
    match = Left(ar(i), InStr(1, ar(i), ",") - 1)
    framenum = Left(ar(i), InStr(1, ar(i), ",") - 1)
    Do While match = framenum
    itm = Split(ar(i), ",")
    ReDim Preserve pts(j + 1) As Double
    pts(j) = CDbl(itm(1)): pts(j + 1) = CDbl(itm(2))
    j = j + 2
    i = i + 1
    If i >= iCount Then
    Exit Do
    End If
    framenum = Left(ar(i), InStr(1, ar(i), ",") - 1)
    If match <> framenum Then
    Exit Do
    GoTo DoNext
    End If
    Loop
    Dim opline As AcadLWPolyline
    Set opline = ThisDrawing.ModelSpace.AddLightWeightPolyline(pts)
    Loop
    ThisDrawing.Regen acActiveViewport
    End Sub

Posting Permissions

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