Here is a journal for creating datum planes through three points. Also shown is the data format I have used. I use a line of data for each datum plane. That is nine coordinate numbers and a name string using comma deliminators.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.IO
Imports System.Windows.Forms
Module datumPlane1
Dim s As Session = Session.GetSession()
Dim ui As UI = ui.GetUI()
Dim ufs As UFSession = UFSession.GetUFSession()
Sub Main()
Dim pointsFile 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
'open csv file
Dim fdlg As OpenFileDialog = New OpenFileDialog()
fdlg.Title = "Choose the data file"
fdlg.InitialDirectory = "c:\"
fdlg.Filter = "All files (*.*)|*.*|CSV files (*.csv)|*.csv"
fdlg.FilterIndex = 2
fdlg.RestoreDirectory = True
If fdlg.ShowDialog() = DialogResult.OK Then
pointsFile = fdlg.FileName
' read data and create datum planes
Dim sr As StreamReader = File.OpenText(pointsFile)
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()
End If
End Sub
Public Sub CreateDatumPlane(ByVal pnt1() As Double, ByVal pnt2() As Double, _
ByVal pnt3() As Double, ByVal name1 As String)
Dim workPart As Part = s.Parts.Work
Dim nullFeatures_Feature As Features.Feature = Nothing
Dim pointFeatureBuilder1 As Features.PointFeatureBuilder
pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)
Dim datumPlaneBuilder1 As Features.DatumPlaneBuilder
datumPlaneBuilder1 = workPart.Features.CreateDatumPlaneBuilder(nullFeatures_Feature)
Dim plane1 As Plane
plane1 = datumPlaneBuilder1.GetPlane()
Dim coordinates1 As Point3d = New Point3d(pnt1(0), pnt1(1), pnt1(2))
Dim point1 As Point
point1 = workPart.Points.CreatePoint(coordinates1)
Dim coordinates2 As Point3d = New Point3d(pnt2(0), pnt2(1), pnt2(2))
Dim point2 As Point
point2 = workPart.Points.CreatePoint(coordinates2)
Dim coordinates3 As Point3d = New Point3d(pnt3(0), pnt3(1), pnt3(2))
Dim point3 As Point
point3 = workPart.Points.CreatePoint(coordinates3)
plane1.SetMethod(PlaneTypes.MethodType.ThreePoints)
Dim geom1(2) As NXObject
geom1(0) = point1
geom1(1) = point2
geom1(2) = point3
plane1.SetGeometry(geom1)
Dim feature1 As Features.Feature
feature1 = datumPlaneBuilder1.CommitFeature()
Dim datumPlaneFeature1 As Features.DatumPlaneFeature = CType(feature1, Features.DatumPlaneFeature)
Dim datumPlane1 As DatumPlane
datumPlane1 = datumPlaneFeature1.DatumPlane
datumPlane1.SetName(name1)
datumPlaneBuilder1.Destroy()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Data File Format:
0,0,0,100,0,0,0,100,0,PLANE1
0,0,0,100,0,0,0,0,100,PLANE2
0,0,0,0,100,0,0,0,100,PLANE3
Frank Swinkels