×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Creation of Datum Plane from 3 points in a Text File
2

Creation of Datum Plane from 3 points in a Text File

Creation of Datum Plane from 3 points in a Text File

(OP)
I am looking to create a datum plane from three points in a text file. I recorded a journal of making a datum plane with three points already in a part file, but the journal was very large with a lot of expression variables and other things that didn't seem necessary.

In the following thread (thread561-284673: Grip code that reads in a CSV text file of points?) cowski linked a journal file that would bring in points from a .csv file. This file works for the text files that I have. I am wondering if anyone has any experience creating datum planes from three points. I am sure it can be done much simpler than my 28kb journal file would indicate.

RE: Creation of Datum Plane from 3 points in a Text File

Will this type of thing happen once, or several times, in each part ?

RE: Creation of Datum Plane from 3 points in a Text File

(OP)
It will happen between 2 and 12 times on each part. I will need to set up a journal to read in three points, create a plane, then read in the next three points, etc...

I'm not sure yet if I will have the user define how many planes will be created or just write the code in such a way to stop once all points have been used. I would assume the latter is possible.

It would also be nice if these planes could be individually named in the part navigator once created, but it is not at all necessary.

RE: Creation of Datum Plane from 3 points in a Text File

Do you want fixed datum planes, or datum planes associative to the points?

www.nxjournaling.com

RE: Creation of Datum Plane from 3 points in a Text File

(OP)
My initial reaction is whichever is easier. The points are never going to move relative to one another once imported and neither will the planes move relative to the points.

There will be a step after importing the points and creating the planes where all the pieces of the part (points, datums, etc..) will be oriented to the WCS, but I don't think the attributes of the planes will matter for this.

 

RE: Creation of Datum Plane from 3 points in a Text File

If you make available a data file that contains the points info I will generate a journal to create the datum planes

Frank Swinkels

RE: Creation of Datum Plane from 3 points in a Text File

2
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

RE: Creation of Datum Plane from 3 points in a Text File

(OP)
That is really great Frank. Thanks for the help.

How hard would it be to modify it for files that have one point coordinate per line? I am talking to the people writing the code that will output the files from a scanning system, but they are unsure what the final format will be. My test files have been structured with one point per line, and I have just modified the files to look like what this code accepts. Hopefully they can just output files that look like this, but if not I would like to have a backup plan as it were.

Again, thanks for the help. I really appreciate it.

RE: Creation of Datum Plane from 3 points in a Text File

Not a problem regarding data format.  All that is required is consistancy. How do you want to include the name?

Frank Swinkels

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources