Forums:
Hi All,
I would like to get the part name from the selected drafting edge. Please look at below code which let me select drafting curve (hole and threaded hole are the most important for me). I need to find parents of selected curve and FEATURE name selected curve where I can find e.g. hole depth, tap depth, thread size ... , generally all hole package information.
Could you help me with this?
I use NX10
Thanks
Marcin
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UFImports NXOpenUI Module SelectDraftingEdge Dim theSession As Session = Session.GetSession()Dim workPart As Part = theSession.Parts.WorkDim displayPart As Part = theSession.Parts.DisplayDim lw As ListingWindow = theSession.ListingWindowDim theUfSession As UFSession = UFSession.GetUFSessionDim theUI As UI = UI.GetUI Sub Main() Dim mySelViewTag As Tag = Tag.NullDim mySelEdgeTag As Tag =NothingDim myEdgeCurve As DisplayableObject lw.open() If IsNothing(theSession.Parts.Work)Then'active part required lw.WriteLine(" no active part, exiting journal")ReturnEndIf Dim currentApplication AsInteger theUfSession.UF.AskApplicationModule(currentApplication) IfNot currentApplication = UFConstants.UF_APP_DRAFTINGThen theUI.NXMessageBox.Show("Error !!!", NXMessageBox.DialogType.Error, "Journal will be working only in ""DRAFTING"" module")ExitSub EndIf Const undoMarkName AsString="Select Drafting Edge"Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName) Do Until UserSelectEdge("Select edge", mySelViewTag, mySelEdgeTag)= Selection.Response.Cancel myEdgeCurve = Utilities.NXObjectManager.Get(mySelEdgeTag)If IsNothing(myEdgeCurve)Then lw.WriteLine(" UserSelectEdge() returned Nothing, skip to next edge selection")exitsubEndIf lw.WriteLine(" selected object type: "& myEdgeCurve.GetType.ToString) lw.writeline(" Tag: "& myEdgeCurve.Tag)Dim selView As NXOpen.View= Utilities.NXObjectManager.Get(mySelViewTag) lw.WriteLine(" selected in view: "& selView.Name) lw.WriteLine(" View type: "& selView.GetType.ToString) Loop lw.Close() EndSub Function UserSelectEdge(ByVal prompt AsString, ByRef theView As Tag, ByRef theObject As Tag)As Selection.Response 'Allow user to interactively select an edgeDim response AsInteger=0Dim user_data As System.IntPtrDim theCursor(2)AsDouble theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)Dim curCursorView AsInteger theUfSession.Ui.AskCursorView(curCursorView) Try theUfSession.Ui.SetCursorView(0)'SelectWithSingleDialog allows the user to make a single selection and returns the object, the point and the view. theUfSession.Ui.SelectWithSingleDialog("Select component: ", prompt, _ UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, AddressOf init_proc_body, _ user_data, response, theObject, theCursor, theView)Finally theUfSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)EndTry IfNot theObject.Equals(Tag.Null)Then theUfSession.Disp.SetHighlight(theObject, 0) Else theUfSession.Ui.SetCursorView(curCursorView)ReturnNothingEndIf SelectCase response Case UFConstants.UF_UI_BACKReturn Selection.Response.BackCase UFConstants.UF_UI_OKReturn Selection.Response.OkCase UFConstants.UF_UI_OBJECT_SELECTEDReturn Selection.Response.ObjectSelectedCase UFConstants.UF_UI_OBJECT_SELECTED_BY_NAMEReturn Selection.Response.ObjectSelectedByNameCaseElseReturn Selection.Response.CancelEndSelectEndFunction PublicFunction init_proc_body(ByVal select_ As IntPtr, _ ByVal userdata As IntPtr)AsInteger'this function must have the same signature as UFUi.SelInitFnT Delegate 'setup mask to filter for edges or curvesDim num_triples AsInteger=1Dim mask_triples(num_triples -1)As UFUi.Mask mask_triples(0).object_type= UFConstants.UF_circle_type mask_triples(0).object_subtype= UFConstants.UF_all_subtype theUfSession.Ui.SetSelMask(select_, _ UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _ num_triples, mask_triples) Return UFConstants.UF_UI_SEL_SUCCESS EndFunction End Module