Forums:
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.CollectionsImports System.Collections.Generic Imports NXOpen Imports NXOpen.UFImports NXOpenUI Imports NXOpen.FeaturesImports 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.WorkDim lw As ListingWindow = theSession.ListingWindow() Sub Main() Dim displayPart As Part = theSession.Parts.DisplayDim response As Selection.Response= Selection.Response.CancelDim prompt AsString="Select Position on Face"Dim temptag As Tag = Tag.NullDim cp(2)AsDoubleDim face1 As Face =NothingDim facetag As Tag = Tag.NullDim point1 As Point =NothingDim mySelectedObject As NXObject Dim Name AsString=""Dim test AsStringDim i AsIntegerDim j AsInteger=1Dim FGTag As Tag = Tag.NullDim FGITag As Tag = Tag.NullDim feat_Group AsNew List(Of Tag) Dim MyBody As Body =NothingDim a_body As NXOpen.Tag= NXOpen.Tag.NullDim endPoint As Point3d Dim featuresToGroup As Tag()=Nothing lw.Open() lw.WriteLine("") Start1: facetag = select_point_on_face(prompt, cp)If facetag = Tag.NullThenGoTo 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)AsDoubleDim u1(2)AsDoubleDim v1(2)AsDoubleDim u2(2)AsDoubleDim v2(2)AsDoubleDim norm(2)AsDoubleDim radii(1)AsDoubleDim param(1)AsDouble theUfSession.Modl.AskFaceParm(facetag, cp, param, pt) theUfSession.Modl.AskFaceProps(facetag, param, pt, u1, v1, u2, v2, norm, radii) Dim WcsNorm(2)AsDouble 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: EndSub PublicFunction select_point_on_face(ByVal prompt AsString, ByRef cp()AsDouble)As NXOpen.TagDim resp AsInteger=0Dim face1 As Face =NothingDim theView As NXOpen.Tag= NXOpen.Tag.NullDim 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_SELECTEDOr resp = UFConstants.UF_UI_OBJECT_SELECTED_BY_NAMEThen ask_pos_on_obj(facetag, cp) theUfSession.Disp.SetHighlight(facetag, 0)Return facetag EndIfReturn Tag.NullEndFunction PublicSub map_view2abs(ByRef c()AsDouble)Dim vname AsString=""Dim abs_mx()AsDouble={0, 0, 0, 1, 0, 0, 0, 1, 0}Dim vw()AsDouble={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}Dim mx()AsDouble={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}Dim irc AsInteger=0 theUfSession.Ui.AskLastPickedView(vname)Dim wp As Part = theSession.Parts.WorkDim 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)EndSub PublicSub map_abs2view(ByRef c()AsDouble)Dim vname AsString=""Dim abs_mx()AsDouble={0, 0, 0, 1, 0, 0, 0, 1, 0}Dim vw()AsDouble={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}Dim mx()AsDouble={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}Dim irc AsInteger=0 theUfSession.Ui.AskLastPickedView(vname)Dim wp As Part = theSession.Parts.WorkDim 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)EndSub PublicSub ask_pos_on_obj(ByVal obj As NXOpen.Tag, ByValloc()AsDouble)Dim aLine As NXOpen.Tag= NXOpen.Tag.NullDim cp()AsDouble={0, 0, 0}Dim dist AsDouble=0Dim lp As UFCurve.LineDim sp(2)AsDoubleDim ep(2)AsDouble 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)EndSub PublicFunction mask_for_face(ByVal select_ As IntPtr, ByVal userdata As IntPtr)AsInteger Dim num_triples AsInteger=1Dim 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_SUCCESSEndFunction PublicFunction PointFeatureOnFace(ByValwhereAs 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=NothingDim pointFeatureBuilder1 As Features.PointFeatureBuilder pointFeatureBuilder1 = workpart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature) pointFeatureBuilder1.Point= point1 Dim nXObject1 As NXObject = pointFeatureBuilder1.Commit() pointFeatureBuilder1.Destroy()Return point1 EndFunction PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger GetUnloadOption = NXOpen.Session.LibraryUnloadOption.ImmediatelyEndFunctionEndModule <vbnet>