Here's a journal found on this forum. It can only be preformed on display part. How to make it functional on "work part".
Option Strict Off
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Features
Imports NXOpen.Utilities
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim ui As UI = UI.GetUI()
Dim workpart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow()
Sub Main()
Dim displayPart As Part = theSession.Parts.Display
Dim response As Selection.Response = Selection.Response.Cancel
Dim prompt As String = "Select Position on Face"
Dim temptag As Tag = Tag.Null
Dim cp(2) As Double
Dim face1 As Face = Nothing
Dim facetag As Tag = Tag.Null
Dim point1 As Point = Nothing
Dim mySelectedObject As NXObject
Dim Name As String = ""
Dim test As String
Dim i As Integer
Dim j As Integer = 1
Dim FGTag As Tag = Tag.Null
Dim FGITag As Tag = Tag.Null
Dim feat_Group As New List(Of Tag)
Dim MyBody As Body = Nothing
Dim a_body As NXOpen.Tag = NXOpen.Tag.Null
Dim endPoint As Point3d
Dim featuresToGroup As Tag() = Nothing
lw.Open()
lw.WriteLine("")
Start1:
facetag = select_point_on_face(prompt, cp)
If facetag = Tag.Null Then GoTo End1
face1 = NXObjectManager.Get(facetag)
Dim pnt3d As Point3d = New Point3d(cp(0), cp(1), cp(2))
point1 = PointFeatureOnFace(pnt3d)
i += 1
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
Dim param(1) As Double
theUfSession.Modl.AskFaceParm(facetag, cp, param, pt)
theUfSession.Modl.AskFaceProps(facetag, param, pt, u1, v1, u2, v2, norm, radii)
Dim WcsNorm(2) As Double
theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, norm, UFConstants.UF_CSYS_ROOT_WCS_COORDS, WcsNorm)
lw.WriteLine("X:" & (norm(0)).ToString & " Y:" &
(norm(1)).ToString & " Z:" &
(norm(2)).ToString)
lw.WriteLine("XC: " & WcsNorm(0).ToString & " YC: " & WcsNorm(1).ToString & " ZC: " & WcsNorm(2).ToString)
GoTo Start1
End1:
End Sub
Public Function select_point_on_face(ByVal prompt As String,
ByRef cp() As Double) As NXOpen.Tag
Dim resp As Integer = 0
Dim face1 As Face = Nothing
Dim theView As NXOpen.Tag = NXOpen.Tag.Null
Dim mask_face As UFUi.SelInitFnT = AddressOf mask_for_face
Dim facetag As Tag = Tag.Null
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
theUfSession.Ui.SelectWithSingleDialog("Select a face", prompt, UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY,
mask_face, Nothing, resp, facetag, cp, theView)
theUfSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
If resp = UFConstants.UF_UI_OBJECT_SELECTED Or resp = UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
ask_pos_on_obj(facetag, cp)
theUfSession.Disp.SetHighlight(facetag, 0)
Return facetag
End If
Return Tag.Null
End Function
Public Sub map_view2abs(ByRef c() As Double)
Dim vname As String = ""
Dim abs_mx() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
Dim vw() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Dim mx() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Dim irc As Integer = 0
theUfSession.Ui.AskLastPickedView(vname)
Dim wp As Part = theSession.Parts.Work
Dim lastViewPicked As View = CType(wp.ModelingViews.FindObject(vname), ModelingView)
Dim vmx As Matrix3x3 = lastViewPicked.Matrix()
vw(3) = vmx.Xx
vw(4) = vmx.Xy
vw(5) = vmx.Xz
vw(6) = vmx.Yx
vw(7) = vmx.Yy
vw(8) = vmx.Yz
vw(9) = vmx.Zx
vw(10) = vmx.Zy
vw(11) = vmx.Zz
theUfSession.Trns.CreateCsysMappingMatrix(vw, abs_mx, mx, irc)
theUfSession.Trns.MapPosition(c, mx)
End Sub
Public Sub map_abs2view(ByRef c() As Double)
Dim vname As String = ""
Dim abs_mx() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
Dim vw() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Dim mx() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Dim irc As Integer = 0
theUfSession.Ui.AskLastPickedView(vname)
Dim wp As Part = theSession.Parts.Work
Dim lastViewPicked As View =
CType(wp.ModelingViews.FindObject(vname), ModelingView)
Dim vmx As Matrix3x3 = lastViewPicked.Matrix()
vw(3) = vmx.Xx
vw(4) = vmx.Xy
vw(5) = vmx.Xz
vw(6) = vmx.Yx
vw(7) = vmx.Yy
vw(8) = vmx.Yz
vw(9) = vmx.Zx
vw(10) = vmx.Zy
vw(11) = vmx.Zz
theUfSession.Trns.CreateCsysMappingMatrix(abs_mx, vw, mx, irc)
theUfSession.Trns.MapPosition(c, mx)
End Sub
Public Sub ask_pos_on_obj(ByVal obj As NXOpen.Tag, ByVal loc() As Double)
Dim aLine As NXOpen.Tag = NXOpen.Tag.Null
Dim cp() As Double = {0, 0, 0}
Dim dist As Double = 0
Dim lp As UFCurve.Line
Dim sp(2) As Double
Dim ep(2) As Double
lp.start_point = sp
lp.end_point = ep
map_abs2view(loc)
lp.start_point(0) = loc(0)
lp.start_point(1) = loc(1)
lp.start_point(2) = loc(2) + 10000
lp.end_point(0) = loc(0)
lp.end_point(1) = loc(1)
lp.end_point(2) = loc(2) - 10000
map_view2abs(lp.start_point)
map_view2abs(lp.end_point)
theUfSession.Curve.CreateLine(lp, aLine)
theUfSession.Modl.AskMinimumDist(obj, aLine, 0, cp, 0, cp, dist, loc, cp)
theUfSession.Obj.DeleteObject(aLine)
End Sub
Public Function mask_for_face(ByVal select_ As IntPtr, ByVal userdata As IntPtr) As Integer
Dim num_triples As Integer = 1
Dim mask_triples(0) As UFUi.Mask
mask_triples(0).object_type = UFConstants.UF_solid_type
mask_triples(0).object_subtype = 0
mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
theUfSession.Ui.SetSelMask(select_,
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific,
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
Public Function PointFeatureOnFace(ByVal where As Point3d) As Point
Dim markId1 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Point")
Dim point1 As Point
point1 = workpart.Points.CreatePoint(where)
Dim nullFeatures_Feature As Features.Feature = Nothing
Dim pointFeatureBuilder1 As Features.PointFeatureBuilder
pointFeatureBuilder1 = workpart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)
pointFeatureBuilder1.Point = point1
Dim nXObject1 As NXObject = pointFeatureBuilder1.Commit()
pointFeatureBuilder1.Destroy()
Return point1
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
re: point on face
This journal makes use of some functions that only work on the displayed part. The easy way to get this journal to work would be to make the part of interest the display part. Depending on your version of NX, right click on the desired component and use "make display part" or "open in new window". This will make the component the display and work part. Run the code in this part.