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.
Hello,
I don't think you need vba.
Have a look:
communities.bentley.com/.../79736.aspx
Laurent
Hi,
This should be a simple vba.
1) Open your file
2) Start your line command
In a Do Loop:
3) read a line from the file
4) There is a split command so you can split the text line at the commas
5) Take the Val() of each x,y, & z number
6) do a Point3dCreateFromXYZ with your x,y,z values
7) SendDataPoint to Microstation with your new point
Loop
9) Close your txt file
10) start your default tool.
So generally, there are two parts of the process, reading from a text file, and sending points to Microstation. Both are relatively easy. Where are you having issues and what does your code look like so far?
--Robert
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)
End If
Close #1
Set oEl = Nothing
Thank you very much jhartog that was exactly what I needed!