' ' This allows you to select a face in a component part. ' ' It then reports the position of the U and V center of ' that face relative to the absolute CSYS of the component part. ' Option Strict Off Imports System Imports NXOpen Imports NXOpenUI Imports NXOpen.UI Imports NXOpen.Utilities Imports NXOpen.UF Module evaluate_selected_component_face_position Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = s.ListingWindow Sub Main() Try ufs.Ui.SetCursorView(0) Dim thisFace As Face = Nothing Dim prototype As NXOpen.Tag = NXOpen.Tag.Null Dim response As Integer = 0 Dim owningPart As NXOpen.Tag = NXOpen.Tag.Null Dim previousPart As NXOpen.Tag = s.Parts.Work.Tag ' NXOpen.Tag.Null Dim uvminmax() As Double = {0, 0, 0, 0} Dim u_midpt As Double = 0 Dim v_midpt As Double = 0 response = SelectFace(thisFace) If response > 0 Then lw.Open() lw.WriteLine("No face selected.") Return End If If ufs.Assem.IsOccurrence(thisFace.Tag) Then prototype = ufs.Assem.AskPrototypeOfOcc(thisFace.Tag) Else prototype = thisFace.Tag End If 'lw.WriteLine("prototype " & prototype.ToString) ufs.Obj.AskOwningPart(prototype, owningPart) ufs.Assem.SetWorkPartQuietly(owningPart, previousPart) 'ufs.Assem.SetWorkPart(owningPart, previousPart) ufs.Disp.SetHighlight(thisFace.Tag, 0) Dim deriv_req As Integer = UFConstants.UF_MODL_EVAL Dim parms(1) As Double ' ======================= get the parms at the UV midpt of the face ufs.Modl.AskFaceUvMinmax(prototype, uvminmax) u_midpt = (uvminmax(0) + uvminmax(1)) / 2 v_midpt = (uvminmax(2) + uvminmax(3)) / 2 parms(0) = u_midpt parms(1) = v_midpt Dim eval_rslt As NXOpen.UF.ModlSrfValue = Nothing '======================== evaluate the face ufs.Modl.EvaluateFace(prototype, deriv_req, parms, eval_rslt) lw.Open() lw.WriteLine("Position: X " & _ eval_rslt.srf_pos(0).ToString() & " Y " & _ eval_rslt.srf_pos(1).ToString() & " Z " & _ eval_rslt.srf_pos(2).ToString()) ufs.Assem.SetWorkPartQuietly(previousPart, owningPart) Catch ex As Exception lw.Open() lw.WriteLine(ex.ToString()) End Try End Sub ' ---------------------------------------------- ' select a face ' ---------------------------------------------- Public Function SelectFace(ByRef selectedObject As NXObject) As Integer Dim ui As UI = GetUI() Dim message As String = "Face:" Dim title As String = "Select Face:" Dim scope As Selection.SelectionScope = _ Selection.SelectionScope.AnyInAssembly Dim keepHighlighted As Boolean = True Dim includeFeatures As Boolean = False Dim response As Selection.Response Dim selectionAction As Selection.SelectionAction = _ Selection.SelectionAction.ClearAndEnableSpecific Dim selectionMask_array(1) As Selection.MaskTriple With selectionMask_array(0) .Type = UFConstants.UF_face_type .Subtype = 0 ' UFConstants.UF_solid_face_subtype '.SolidBodySubtype = 0 End With Dim cursor As Point3d response = ui.SelectionManager.SelectObject(message, title, scope, _ selectionAction, includeFeatures, _ keepHighlighted, selectionMask_array, _ selectedObject, cursor) If response = Selection.Response.Cancel Or _ response = Selection.Response.Back Then Return 1 Else Return 0 End If End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End Module