Results 1 to 20 of 53

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular fixo's Avatar
    Joined
    Jul 2006
    Location
    Sankt-Petersburg
    Posts
    99
    Location
    Quote Originally Posted by Zrob
    Hi Guys,

    Does anyone here have experience plotting points in AutoCAD using VBA from a txt file? If so can you post an example of one.

    Thanks for any advice on how I should get started.

    Rob
    Hope this will get you started
    Source file is a comma delimited text file
    Change full path of this file (blue colored)

     
    Public Sub DrawPointsFromTextFile()
    Dim fd As Long
    Dim sline As String
    Dim ar As Variant
    fd = FreeFile
    Open "C:\Temp\Coordinates.txt" For Input Access Read Shared As fd
    Do Until EOF(fd)
    Line Input #fd, sline
    ar = Split(sline, ",")
    ReDim pt(UBound(ar)) As Double
    Dim i As Integer
    For i = 0 To UBound(ar)
       pt(i) = CDbl(ar(i))
    Next i
    ThisDrawing.ModelSpace.AddPoint pt
    Loop
    Close fd
    End Sub
    ~'J'~

  2. #2
    Hi Guys!

    Tommy, I would like to plot points in model space, by reading the info out of a text file. Basically I have a offset chart for a small boat, so I am converting all the data that they give in Ft-In-1/16 the way boat builders do, and I wrote a C++ program that converts that to a decimal, and I write it to a text file. But now I would lke to read that in with VBA in AutoCAD and need help on that end.

    Fatty, thanks for that example!

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

  3. #3
    VBAX Regular fixo's Avatar
    Joined
    Jul 2006
    Location
    Sankt-Petersburg
    Posts
    99
    Location
    Hi, Rob

    Can you upload here a small part of this
    text file to see how it looks like?
    Guess, there is need to convert imperic
    to decimals to draw the points with accuracy

    ~'J'~

  4. #4
    Sure, I was going to do that but I had some problems uploading last night, let me try again. I have two pics that explane my 2 txt files, but I think I should only make or tun it into one file, so let me know and I wil tailor that part of it for you if needed.

    But basically one file has the frame spacing in the Z direction, the other one file has the data for half the side profile(seen here), then you would just mirror that later on.
    Last edited by Zrob; 04-12-2008 at 07:08 AM.
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  5. #5
    Frame Profiles txt explanation, I can adjust this output.
    Last edited by Zrob; 04-12-2008 at 07:04 AM.
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  6. #6
    And the actual txt docs in a zip file with all items. In this post, let me know what you think.


    Thanks For any help with this and if you need me to change the config files let me know and I will.
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  7. #7
    VBAX Regular fixo's Avatar
    Joined
    Jul 2006
    Location
    Sankt-Petersburg
    Posts
    99
    Location
    Hi Rob,
    I need a time to chew it
    I'll try

    ~'J'~

  8. #8
    VBAX Regular fixo's Avatar
    Joined
    Jul 2006
    Location
    Sankt-Petersburg
    Posts
    99
    Location
    Quote Originally Posted by Zrob
    And the actual txt docs in a zip file with all items. In this post, let me know what you think.


    Thanks For any help with this and if you need me to change the config files let me know and I will.
    It's me again
    I don't understand completely your task, sorry
    Here is what I could to write so far
    I hope somebody else will help you with second part

     
    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
    ~'J'~

Posting Permissions

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