Extracting Point Set From Face(s)

I am looking for a method to extract points(.001" spacing between points) from all visible faces in the work view and export them to a text file. If anyone has a journal that can extract points from a single face, that would give me a good place to start. I am attempting to put a journal together to analyze the complexity of machining for large parts. The direction I am leaning towards currently is extracting a point set from the faces and creating custom algorithms to analyze and find complex locations on these parts. Thanks in advanced for you time.

I'd suggest looking into the UF_MODL_ask_face_props function. Given a U,V point on a face, it will return a point location, first and second derivatives, and radius of curvature of the face. The UF_MODL_ask_face_uv_minmax function can be used in conjunction to set limits as you iterate over the face of interest.




I can try to put together a quick demo journal if you are interested.

That sounds like what I need, I would be very interested in this demo journal.

DHuskic
Nx 9 VB

Is there a way to only select the faces I can see on a solid model from the "Top" view?

DHuskic
Nx 9 VB

It will take a bit of work, but I'm 99% sure it can be done. My first inclination would be to use the UF_MODL_trace_a_ray function to iterate over the area returned by the bounding box function to get the face(s) of interest.

You can find some code at eng-tips that may give you a starting point, or at least some ideas:
http://www.eng-tips.com/viewthread.cfm?qid=350411

(Thanks Frank!)

Here's some code that will hopefully get you started:





Option Strict Off
Imports System
Imports System.Data
Imports NXOpen
Imports NXOpen.UF

Module points_on_face

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim theFace As Face
If SelectFace("select a face", theFace) = Selection.Response.Cancel Then
Return
End If

Dim myDocs As String
myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim outputFile As String = IO.Path.Combine(myDocs, "FaceData.csv")

Dim faceTable As New DataTable("Face")
faceTable.Columns.Add("ID", GetType(Integer))
faceTable.Columns.Add("U", GetType(Double))
faceTable.Columns.Add("V", GetType(Double))
faceTable.Columns.Add("X", GetType(Double))
faceTable.Columns.Add("Y", GetType(Double))
faceTable.Columns.Add("Z", GetType(Double))
faceTable.Columns.Add("U1_X", GetType(Double))
faceTable.Columns.Add("U1_Y", GetType(Double))
faceTable.Columns.Add("U1_Z", GetType(Double))
faceTable.Columns.Add("V1_X", GetType(Double))
faceTable.Columns.Add("V1_Y", GetType(Double))
faceTable.Columns.Add("V1_Z", GetType(Double))
faceTable.Columns.Add("U2_X", GetType(Double))
faceTable.Columns.Add("U2_Y", GetType(Double))
faceTable.Columns.Add("U2_Z", GetType(Double))
faceTable.Columns.Add("V2_X", GetType(Double))
faceTable.Columns.Add("V2_Y", GetType(Double))
faceTable.Columns.Add("V2_Z", GetType(Double))
faceTable.Columns.Add("norm_X", GetType(Double))
faceTable.Columns.Add("norm_Y", GetType(Double))
faceTable.Columns.Add("norm_Z", GetType(Double))
faceTable.Columns.Add("radius_U", GetType(Double))
faceTable.Columns.Add("radius_V", GetType(Double))

Dim uvMinMax(3) As Double
theUfSession.Modl.AskFaceUvMinmax(theFace.Tag, uvMinMax)

lw.WriteLine("U min: " & uvMinMax(0).ToString)
lw.WriteLine("U max: " & uvMinMax(1).ToString)
lw.WriteLine("V min: " & uvMinMax(2).ToString)
lw.WriteLine("V max: " & uvMinMax(3).ToString)

Const numPtsU As Integer = 10
Const numPtsV As Integer = 10
Dim stepU As Double = (uvMinMax(1) - uvMinMax(0)) / numPtsU
Dim stepV As Double = (uvMinMax(3) - uvMinMax(2)) / numPtsV

'time variables to record how long the operation took
Dim startTime As DateTime = Now
Dim endTime As DateTime
Dim timeElapsed As TimeSpan

For iu As Integer = 0 To numPtsU
For iv As Integer = 0 To numPtsV
Dim param(1) As Double
param(0) = uvMinMax(0) + iu * stepU
param(1) = uvMinMax(2) + iv * stepV

Dim pt(2) As Double
Dim u1(2) As Double
Dim v1(2) As Double
Dim u2(2) As Double
Dim v2(2) As Double
Dim norm(2) As Double
Dim radii(1) As Double

theUfSession.Modl.AskFaceProps(theFace.Tag, param, pt, u1, v1, u2, v2, norm, radii)
faceTable.Rows.Add(theFace.Tag, param(0), param(1), _
pt(0), pt(1), pt(2), _
u1(0), u1(1), u1(2), _
v1(0), v1(1), v1(2), _
u2(0), u2(1), u2(2), _
v2(0), v2(1), v2(2), _
norm(0), norm(1), norm(2), _
radii(0), radii(1))

Next
Next

endTime = Now
timeElapsed = endTime.Subtract(startTime)
lw.WriteLine("finished collecting surface data")
lw.WriteLine("Time elapsed: " & timeElapsed.ToString)
lw.WriteLine("")

' Create DataView
Dim view As New DataView(faceTable)

'write data to CSV file
Using myWriter As New IO.StreamWriter(outputFile, False)
myWriter.WriteLine("Face Tag, U param, V param, point(X), point(Y), point(Z), U'(X), U'(Y), U'(Z), V'(X), V'(Y), V'(Z), U''(X), U''(Y), U''(Z), V''(X), V''(Y), V''(Z), normal(X), normal(Y), normal(Z), radius(U), radius(V)")
For Each row As DataRowView In view
myWriter.WriteLine(row("ID") & "," & row("U") & "," & row("V") & "," & _
row("X") & "," & row("Y") & "," & row("Z") & "," & _
row("U1_X") & "," & row("U1_Y") & "," & row("U1_Z") & "," & _
row("V1_X") & "," & row("V1_Y") & "," & row("V1_Z") & "," & _
row("U2_X") & "," & row("U2_Y") & "," & row("U2_Z") & "," & _
row("V2_X") & "," & row("V2_Y") & "," & row("V2_Z") & "," & _
row("norm_X") & "," & row("norm_Y") & "," & row("norm_Z") & "," & _
row("radius_U") & "," & row("radius_V"))
Next
End Using

lw.WriteLine("face data written to: " & outputFile)

Diagnostics.Process.Start(outputFile)

End Sub

Function SelectFace(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a face"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

End Module

Hi,

I need to do the exact same thing (extracting surface information) using journal in C++, which is new to me. Do all these commands have equivalent in C++? Any suggestion would be helpful. Is there any website like NX journaling where i can find C++ sample codes??
Thanks

If you're new to all this, I recommend that you use VB or C# rather than C++. The .NET API and languages are much easier, which is why so many people use them.

Hi, thank you for the help! I have a small question.. Is it possible to get Face properties in new worksheet rather than new excel file?
Thanks.

The short answer is "yes it is possible". To do so, you will need to open the Excel file of interest, add a worksheet (if needed) and write the values to the worksheet rather than to a text file. If you search for "Excel" on this website, you will find several journals that show how to open Excel and write values to a worksheet.

Hello, I am looking for a quicker function than AskFaceProps, it gets bogged down a lot of u/v points on the face, and all I need returned is the x, y, and z values corresponding to that u/v point. I don't need all the extra data. Does anyone have any ideas?

DHuskic
Nx 9 VB

The "point set" command allows you to create points on a face based on the U and V percentage. I don't know how the speed would compare to the AskFaceProps function...

There is a version of the CreatePoint method that allows you to create points on the UV parameters of a face. This would be more direct than using the "point set" command mentioned in my previous post.

The "point set" command might be advantageous if you are creating a large number of points; might need some testing to see which is better for your application.