Hi everyone, I am stuck with a task and was wondering if anyone could help me.
I am trying to create a VBA that will import the XYZ points for a line from a text file?
For example, line 1 of the text file is
683828.7102,7618574.5459,0.0000
Line 2 is
683847.0212,7618567.7979,0.0000
I have litteraly thousands of lines like this and dont want to have to create a million lines in VBA giving each lines x y and z value, that would take longer than importing from the xyz text tool and drawing lines in, connecting the dots.
Is there a way to have a VBA open the text file and work through each line, importing the XYZs and then moving to the next line drawing a line string as it goes?
Thank you very much for your help.
Yes, it can be done in VBA. Something like this (Warning: I haven't tested this code):
Dim X, Y, Z
Dim startPt As Point3d, endPt As Point3d, oEl As LineElement
Open "D:\testfile.txt" For Input As #1
If Not EOF(1) Then
Input #1, X, Y, Z
startPt = Point3dFromXYZ(X, Y, Z)
Do While Not EOF(1)
endPt = Point3dFromXYZ(X, Y, Z)
Set oEl = CreateLineElement2(Nothing, startPt, endPt)
ActiveModelReference.AddElement oEl
oEl.Redraw
startPt = Point3dFromXYZ(endPt.X, endPt.Y, endPt.Z)
Loop
End If
Close #1
Set oEl = Nothing
Thank you very much jhartog that was exactly what I needed!