kfraysur
Bioengineer
- Feb 4, 2010
- 42
I am looking to add to a journal to create some datum CSYS.
Currently, the journal will path to and import two text files. The first text file contains coordinates for three sets of points that are used to create a plane. Big shoutout to FrankSwinks for helping me with that task in this thread: thread561-317741. That code looks like this:
The second text file contains coordinates for sets of three points. Each set will correspond to one of the planes imported from the previous file, and the third point in each group will intersect with the corresponding datum plane previously created (so point 3 will intersect with plane 1, point 6 will intersect with plane 2, and so on) These points are imported as below (Big ups to cowski in this thread: thread561-284673 for the assist here):
The previous code also saved the coordinates of the first and last point that intersected with the created planes. I use these points to create a line and find the midpoint of that line in the following code (Big ups to cowski again here as I got this info from his excellent site [URL unfurl="true"]http://www.nxjournaling.com[/url]):
So now that we've talked about what I can do, now I want to shift gears to what I want to do. I would like this journal to use the created points, planes, and lines to create a datum CSYS that will be oriented such that the X-axis is normal the the created datum plane, the Y-axis is pointing back toward the midpoint of the line we previously created, and its origin is at the point that intersects with the datum plane. I'm sure I worded this poorly, so I have attached a picture.
Any help would be greatly appreciated. Thanks in advance for your time and thanks for reading all this.
Currently, the journal will path to and import two text files. The first text file contains coordinates for three sets of points that are used to create a plane. Big shoutout to FrankSwinks for helping me with that task in this thread: thread561-317741. That code looks like this:
Code:
Dim planesFile As String
Dim linestring As String = Nothing
Dim testArray() As String
Dim pnt1(2) As Double
Dim pnt2(2) As Double
Dim pnt3(2) As Double
Dim temptag As Tag = Tag.Null
Dim name1 As String = Nothing
planesFile = [highlight #FCE94F]FILE PATH DATA GOES HERE[/highlight]
' read data and create datum planes
Dim sr As StreamReader = File.OpenText(planesFile)
Try
Do While sr.Peek >= 0
linestring = sr.ReadLine
testArray = Split(linestring, ",", 10)
pnt1(0) = CType(testArray(0), Double)
pnt1(1) = CType(testArray(1), Double)
pnt1(2) = CType(testArray(2), Double)
pnt2(0) = CType(testArray(3), Double)
pnt2(1) = CType(testArray(4), Double)
pnt2(2) = CType(testArray(5), Double)
pnt3(0) = CType(testArray(6), Double)
pnt3(1) = CType(testArray(7), Double)
pnt3(2) = CType(testArray(8), Double)
name1 = testArray(9)
CreateDatumPlane(pnt1, pnt2, pnt3, name1)
Loop
Catch ex As Exception
MsgBox("Wrong data format")
End Try
sr.Close()
sr.Dispose()
The second text file contains coordinates for sets of three points. Each set will correspond to one of the planes imported from the previous file, and the third point in each group will intersect with the corresponding datum plane previously created (so point 3 will intersect with plane 1, point 6 will intersect with plane 2, and so on) These points are imported as below (Big ups to cowski in this thread: thread561-284673 for the assist here):
Code:
Dim pointsFile as String
Dim num_points As Long
Dim x As Double
Dim y As Double
Dim z As Double
Dim strlines() As String
Dim strline() As String
'initializing variables for the alignment line on layer 62
Dim AlignLinePoint1 as Point3d
Dim AlignLinePoint2 as Point3d
pointsFile = [highlight #FCE94F]FILE PATH DATA GOES HERE[/highlight]
Dim tmpstream As StreamReader = File.OpenText(pointsFile)
'read the points into an array
'Load content of file to strLines array
strlines = tmpstream.ReadToEnd().Split(Environment.NewLine)
' Count number of points
num_points = UBound(strlines)
Dim i As Integer
for i = 0 to num_points - 1
strline = strlines(i).Split(",")
x = CDbl(strline(0))
y = CDbl(strline(1))
z = CDbl(strline(2))
Dim coordinates1 As Point3d = New Point3d(x, y, z)
Dim point1 As Point
point1 = workPart.Points.CreatePoint(coordinates1)
point1.SetVisibility(SmartObject.VisibilityOption.Visible)
point1.RedisplayObject()
coordinates1 = nothing
point1 = nothing
'Saves x,y,and z coordinates for the Alignment Line Point 1
If i = 2 Then
AlignLinePoint1.x = x
AlignLinePoint1.y = y
AlignLinePoint1.z = z
End If
'Saves x,y,and z coordinates for the Alignment Line Point 2
If i = num_points - 1 Then
AlignLinePoint2.x = x
AlignLinePoint2.y = y
AlignLinePoint2.z = z
End If
next
The previous code also saved the coordinates of the first and last point that intersected with the created planes. I use these points to create a line and find the midpoint of that line in the following code (Big ups to cowski again here as I got this info from his excellent site [URL unfurl="true"]http://www.nxjournaling.com[/url]):
Code:
workPart.Curves.CreateLine(AlignLinePoint1, AlignLinePoint2)
'create scalar representing the 50% distance between two points (midpoint)
Dim distanceScalar As Scalar
distanceScalar = workPart.Scalars.CreateScalar(0.5, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
'create midpoint between Import Points of DPF1 and the last DPF
'Next lines basically shift the point types to 'Point' instead of 'Point3d' due to the incompatibility of the distance scalar
'function for use with the point creation at the midline between two points.
Dim ToeLinePoint1 as Point = workPart.Points.CreatePoint(AlignLinePoint1)
Dim ToeLinePoint2 as Point = workPart.Points.CreatePoint(AlignLinePoint2)
Dim AlignMidPoint As Point
AlignMidPoint = workPart.Points.CreatePoint(ToeLinePoint1, ToeLinePoint2, distanceScalar, SmartObject.UpdateOption.WithinModeling)
AlignMidPoint.RemoveParameters()
AlignMidPoint.SetVisibility(SmartObject.VisibilityOption.Visible)
So now that we've talked about what I can do, now I want to shift gears to what I want to do. I would like this journal to use the created points, planes, and lines to create a datum CSYS that will be oriented such that the X-axis is normal the the created datum plane, the Y-axis is pointing back toward the midpoint of the line we previously created, and its origin is at the point that intersects with the datum plane. I'm sure I worded this poorly, so I have attached a picture.
Any help would be greatly appreciated. Thanks in advance for your time and thanks for reading all this.