reading 3Dpolyline vertices from a file and drawing it in AutoCAD
reading 3Dpolyline vertices from a file and drawing it in AutoCAD
(OP)
I have come across a problem I'm unable to solve:
I have a text file, where each line contain such data as X, Y and Z coordinate and a index number telling whether this point is a separate point (empty or 0) or a member of a 3Dpolyline (for example all points with number 1 are on one polyline and all points with index number 2 are on another polyline). Luckily, if there's a polyline in the file, points on a specific polyline are one after the another.
So, I made a code which reads a line from the file, gets the coordinates and the index number. In a case of a point, it just draws the point but what about the polyline?
' if the index number shows this point is a
' part of a polyline
Case Else
strIndexNumberOfNextInputLine = strIndexNumber
' because the program has already read a line,
' those points have to be assigned as the first
' vertex of a polyline
dbl3DPolylineVertices(0) = Mid(strLine1, 30, 12)
dbl3DPolylineVertices(1) = Mid(strLine1, 47, 12)
dbl3DPolylineVertices(2) = Mid(strLine1, 60, 12)
Do Until strBreaklineNumber <> strIndexNumberOfNextInputLine
intVertexCounter = 3
Line Input #1, strLine1
strBreaklineNumber = LTrim(Mid(strLine1, 9, 8))
dbl3DPolylineVertices(intVertexCounter) = Mid(strLine1, 30, 12)
dbl3DPolylineVertices(intVertexCounter + 1) = Mid(strLine1, 47, 12)
dbl3DPolylineVertices(intVertexCounter + 2) = Mid(strLine1, 60, 12)
intVertexCounter = intVertexCounter + 3
Loop
' now i know how many vertices there are in the line [it was defined as "Dim dbl3DPolylineVertices() as Double"]
ReDim Preserve dbl3DPolylineVertices(0 To intVertexCounter - 3)
Set ent3DPolyline = ThisDrawing.ModelSpace.Add3DPoly(dbl3dpolylineVertices)
I guess the problem is that the vertex information gets lost and the difficultiness of programming because of reading one row at a time from the text file.
I managed to do this when I defined the number of vertices beforehand in the beginning (like "Dim dbl3DPolylineVertices(0 to 5) as Double"), but in my files the polylines can have different number of vertices.
Any ideas how to solve this or make the whole thing better?
Thanks!
Johann.
I have a text file, where each line contain such data as X, Y and Z coordinate and a index number telling whether this point is a separate point (empty or 0) or a member of a 3Dpolyline (for example all points with number 1 are on one polyline and all points with index number 2 are on another polyline). Luckily, if there's a polyline in the file, points on a specific polyline are one after the another.
So, I made a code which reads a line from the file, gets the coordinates and the index number. In a case of a point, it just draws the point but what about the polyline?
' if the index number shows this point is a
' part of a polyline
Case Else
strIndexNumberOfNextInputLine = strIndexNumber
' because the program has already read a line,
' those points have to be assigned as the first
' vertex of a polyline
dbl3DPolylineVertices(0) = Mid(strLine1, 30, 12)
dbl3DPolylineVertices(1) = Mid(strLine1, 47, 12)
dbl3DPolylineVertices(2) = Mid(strLine1, 60, 12)
Do Until strBreaklineNumber <> strIndexNumberOfNextInputLine
intVertexCounter = 3
Line Input #1, strLine1
strBreaklineNumber = LTrim(Mid(strLine1, 9, 8))
dbl3DPolylineVertices(intVertexCounter) = Mid(strLine1, 30, 12)
dbl3DPolylineVertices(intVertexCounter + 1) = Mid(strLine1, 47, 12)
dbl3DPolylineVertices(intVertexCounter + 2) = Mid(strLine1, 60, 12)
intVertexCounter = intVertexCounter + 3
Loop
' now i know how many vertices there are in the line [it was defined as "Dim dbl3DPolylineVertices() as Double"]
ReDim Preserve dbl3DPolylineVertices(0 To intVertexCounter - 3)
Set ent3DPolyline = ThisDrawing.ModelSpace.Add3DPoly(dbl3dpolylineVertices)
I guess the problem is that the vertex information gets lost and the difficultiness of programming because of reading one row at a time from the text file.
I managed to do this when I defined the number of vertices beforehand in the beginning (like "Dim dbl3DPolylineVertices(0 to 5) as Double"), but in my files the polylines can have different number of vertices.
Any ideas how to solve this or make the whole thing better?
Thanks!
Johann.





RE: reading 3Dpolyline vertices from a file and drawing it in AutoCAD
How about:
CODE
Dim dbl3DPolylineVertices() as Double
Dim iCnt as Integer
varArray = Split(strLine1, ",")
' Since the first item is just an indicator:
'
For iCnt = 1 to Ubound(varArray)
If iCnt = 1 Then
Redim dbl3DPolylineVertices(0)
Else
Redim Preserve dbl3DPolylineVertices(iCnt - 1)
End If
dbl3DPolylineVertices(iCnt - 1) = CDbl(varArray(iCnt))
Next iCnt
HTH
Todd
RE: reading 3Dpolyline vertices from a file and drawing it in AutoCAD
What version ACAD are you using?
What is the end use for the code?