nxopen create a "point on face" with vb .net
nxopen create a "point on face" with vb .net
(OP)
Hello everybody,
I'm using NX8.0, and I would like to know if it is possible to create programmatically a "point on face" over U shaped faces or faces with hole(s) inside it, while being sure that the point is not within the gap/hole of the face.
In other words, how to make sure that the point created is over (in contact with) the face and not within the face's gap.
PS: except for the corners, the position of the created point doesn't matter.
Thanks in advance,
Nabil.
I'm using NX8.0, and I would like to know if it is possible to create programmatically a "point on face" over U shaped faces or faces with hole(s) inside it, while being sure that the point is not within the gap/hole of the face.
In other words, how to make sure that the point created is over (in contact with) the face and not within the face's gap.
PS: except for the corners, the position of the created point doesn't matter.
Thanks in advance,
Nabil.





RE: nxopen create a "point on face" with vb .net
CODE -->
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.Utilities Module Select_Point_on_Face Dim s As Session = Session.GetSession() Dim ui As UI = UI.GetUI() Dim ufs As UFSession = UFSession.GetUFSession() Dim workpart As Part = s.Parts.Work Sub Main() 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 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) GoTo Start1 End1: End Sub 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 ufs.Ui.AskLastPickedView(vname) Dim wp As Part = s.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 ufs.Trns.CreateCsysMappingMatrix(vw, abs_mx, mx, irc) ufs.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 ufs.Ui.AskLastPickedView(vname) Dim wp As Part = s.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 ufs.Trns.CreateCsysMappingMatrix(abs_mx, vw, mx, irc) ufs.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) ufs.Curve.CreateLine(lp, aLine) ufs.Modl.AskMinimumDist(obj, aLine, 0, cp, 0, cp, dist, loc, cp) ufs.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 ufs.Ui.SetSelMask(select_, _ UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _ num_triples, mask_triples) Return UFConstants.UF_UI_SEL_SUCCESS End Function Public Function select_point_on_face(ByVal prompt As String, _ ByRef cp() As Double) As NXOpen.Tag Dim resp As Integer = 0 ' Dim thing As NXOpen.Tag = NXOpen.Tag.Null 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 ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) ufs.Ui.SelectWithSingleDialog("Select a face", prompt, _ UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, _ mask_face, Nothing, resp, facetag, cp, theView) ufs.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) ufs.Disp.SetHighlight(facetag, 0) Return facetag End If Return Tag.Null End Function Public Function PointFeatureOnFace(ByVal where As Point3d) As Point Dim markId1 As Session.UndoMarkId = s.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 '----Other unload options------- 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End ModuleRegards
Frank Swinkels
RE: nxopen create a "point on face" with vb .net
thank you very much for your quick answer.
It is a really interesting code however what I need is module that adapt to any face shape and create a point on the face while avoiding the eventual gap on the face and the corners. The ideal would be the nearest position near the centroid but it is compulsory.
I cannot use directly the centroid because if the face has a U form the centroid is created in the gap in between.
Thanks again for your help.
Sincerely,
Nabil