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.UF
Imports NXOpenUI
Module SelectDraftingEdge
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim theUI As UI = UI.GetUI
Sub Main()
Dim mySelViewTag As Tag = Tag.Null
Dim mySelEdgeTag As Tag = Nothing
Dim myEdgeCurve As DisplayableObject
lw.open()
If IsNothing(theSession.Parts.Work) Then
'active part required
lw.WriteLine(" no active part, exiting journal")
Return
End If
Dim currentApplication As Integer
theUfSession.UF.AskApplicationModule(currentApplication)
If Not currentApplication = UFConstants.UF_APP_DRAFTING Then
theUI.NXMessageBox.Show("Error !!!", NXMessageBox.DialogType.Error, "Journal will be working only in ""DRAFTING"" module")
Exit Sub
End If
Const undoMarkName As String = "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")
exit sub
End If
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()
End Sub
Function UserSelectEdge(ByVal prompt As String, ByRef theView As Tag, ByRef theObject As Tag) As Selection.Response
'Allow user to interactively select an edge
Dim response As Integer = 0
Dim user_data As System.IntPtr
Dim theCursor(2) As Double
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Dim curCursorView As Integer
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)
End Try
If Not theObject.Equals(Tag.Null) Then
theUfSession.Disp.SetHighlight(theObject, 0)
Else
theUfSession.Ui.SetCursorView(curCursorView)
Return Nothing
End If
Select Case response
Case UFConstants.UF_UI_BACK
Return Selection.Response.Back
Case UFConstants.UF_UI_OK
Return Selection.Response.Ok
Case UFConstants.UF_UI_OBJECT_SELECTED
Return Selection.Response.ObjectSelected
Case UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME
Return Selection.Response.ObjectSelectedByName
Case Else
Return Selection.Response.Cancel
End Select
End Function
Public Function init_proc_body(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer
'this function must have the same signature as UFUi.SelInitFnT Delegate
'setup mask to filter for edges or curves
Dim num_triples As Integer = 1
Dim 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
End Function
End Module
re: feature from drafting curve
The code in the following link will be a good start:
http://www.eng-tips.com/viewthread.cfm?qid=404222
Part name from the selected Drafting Curve
Many Thanks for answer.
Code which you showed, return feature name for modeling edge.
My goal is create code which will be similar to Hole Callout method dimension but will not be associative.It is mean that e.g, when I change hole depth my dimension not update. I recorded this operation and I need component name and feature name.
Below is code which return part name but working correct when I select THREADED HOLE drafting curve. Not working for another HOLE PACKAGE drafting curve. You have much bigger experience for this so maybe you have any idea?
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module SelectDraftingEdge
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim theUI As UI = UI.GetUI
Sub Main()
Dim mySelViewTag As Tag = Tag.Null
Dim mySelEdgeTag As Tag = Nothing
Dim myEdgeCurve As DisplayableObject
lw.open()
If IsNothing(theSession.Parts.Work) Then
'active part required
lw.WriteLine(" no active part, exiting journal")
Return
End If
Dim currentApplication As Integer
theUfSession.UF.AskApplicationModule(currentApplication)
If Not currentApplication = UFConstants.UF_APP_DRAFTING Then
theUI.NXMessageBox.Show("Error !!!", NXMessageBox.DialogType.Error, "Journal will be working only in ""DRAFTING"" module")
Exit Sub
End If
Const undoMarkName As String = "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")
exit sub
End If
Dim myComponent As Assemblies.Component
Dim dwgObj As NXObject
dwgObj = Utilities.NXObjectManager.Get(mySelEdgeTag)
' *************** Part Name of THREADER HOLE ********************
If TypeOf (dwgObj) Is NXOpen.Drawings.DraftingCurve Then
Dim groupTag As Tag
Dim groupType As Integer
Dim groupSubType As Integer
theUfSession.Obj.AskTypeAndSubtype(dwgObj.Tag, groupType, groupSubType)
Try
if groupType = UFConstants.UF_circle_type
Dim theFaceTag1 As Tag
theUfSession.Draw.AskFaceOfSil(dwgObj.Tag, theFaceTag1)
'lw.WriteLine(" theFaceTag = " & theFaceTag1)
Dim theFace1 As NXObject = Utilities.NXObjectManager.Get(theFaceTag1)
'lw.WriteLine(" theFace = " & theFace1.ToString)
myComponent = theFace1.OwningComponent
End if
Catch e as Exception
'lw.writeline("Failed: "& e.ToString)
End Try
End if
' ***********************************
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)
Try
lw.WriteLine(" File name: " & myComponent.DisplayName)
Catch
lw.writeline("*********************************")
lw.WriteLine("At the moment I am not able to find part name selected HOLE." & VbNewLine & "Please try with THREADED HOLE.")
lw.writeline("*********************************")
End Try
Loop
lw.Close()
End Sub
Function UserSelectEdge(ByVal prompt As String, ByRef theView As Tag, ByRef theObject As Tag) As Selection.Response
'Allow user to interactively select an edge
Dim response As Integer = 0
Dim user_data As System.IntPtr
Dim theCursor(2) As Double
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Dim curCursorView As Integer
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)
End Try
If Not theObject.Equals(Tag.Null) Then
theUfSession.Disp.SetHighlight(theObject, 0)
Else
theUfSession.Ui.SetCursorView(curCursorView)
Return Nothing
End If
Select Case response
Case UFConstants.UF_UI_BACK
Return Selection.Response.Back
Case UFConstants.UF_UI_OK
Return Selection.Response.Ok
Case UFConstants.UF_UI_OBJECT_SELECTED
Return Selection.Response.ObjectSelected
Case UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME
Return Selection.Response.ObjectSelectedByName
Case Else
Return Selection.Response.Cancel
End Select
End Function
Public Function init_proc_body(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer
'this function must have the same signature as UFUi.SelInitFnT Delegate
'setup mask to filter for edges or curves
Dim num_triples As Integer = 1
Dim 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
End Function
End Module
Many thanks for help
Marcin
re: get part from hole edge
I expanded the selection function to allow circular edges to be selected. It will report the component of the selected edge; but I'm not entirely sure that this is what you are looking for.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module SelectDraftingEdge
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim theUI As UI = UI.GetUI
Sub Main()
Dim mySelViewTag As Tag = Tag.Null
Dim mySelEdgeTag As Tag = Nothing
Dim myEdgeCurve As DisplayableObject
lw.open()
If IsNothing(theSession.Parts.Work) Then
'active part required
lw.WriteLine(" no active part, exiting journal")
Return
End If
Dim currentApplication As Integer
theUfSession.UF.AskApplicationModule(currentApplication)
If Not currentApplication = UFConstants.UF_APP_DRAFTING Then
theUI.NXMessageBox.Show("Error !!!", NXMessageBox.DialogType.Error, "Journal will be working only in ""DRAFTING"" module")
Exit Sub
End If
Const undoMarkName As String = "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")
exit sub
End If
Dim myComponent As Assemblies.Component
Dim dwgObj As NXObject
dwgObj = Utilities.NXObjectManager.Get(mySelEdgeTag)
' *************** Part Name of THREADER HOLE ********************
If TypeOf (dwgObj) Is NXOpen.Drawings.DraftingCurve Then
Dim groupTag As Tag
Dim groupType As Integer
Dim groupSubType As Integer
theUfSession.Obj.AskTypeAndSubtype(dwgObj.Tag, groupType, groupSubType)
Try
if groupType = UFConstants.UF_circle_type
Dim theFaceTag1 As Tag
theUfSession.Draw.AskFaceOfSil(dwgObj.Tag, theFaceTag1)
'lw.WriteLine(" theFaceTag = " & theFaceTag1)
Dim theFace1 As NXObject = Utilities.NXObjectManager.Get(theFaceTag1)
'lw.WriteLine(" theFace = " & theFace1.ToString)
myComponent = theFace1.OwningComponent
End if
Catch e as Exception
'lw.writeline("Failed: "& e.ToString)
End Try
End if
' ***********************************
lw.WriteLine(" selected object type: " & myEdgeCurve.GetType.ToString)
lw.writeline(" IsOccurrence: " & myEdgeCurve.IsOccurrence.tostring)
if myEdgeCurve.IsOccurrence then
lw.writeline(" owning component: " & myEdgeCurve.owningComponent.displayname)
lw.writeline(" owning part: " & myEdgeCurve.owningComponent.Prototype.OwningPart.FullPath)
end if
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)
Try
lw.WriteLine(" File name: " & myComponent.DisplayName)
Catch
lw.writeline("*********************************")
lw.WriteLine("At the moment I am not able to find part name selected HOLE." & VbNewLine & "Please try with THREADED HOLE.")
lw.writeline("*********************************")
End Try
Loop
lw.Close()
End Sub
Function UserSelectEdge(ByVal prompt As String, ByRef theView As Tag, ByRef theObject As Tag) As Selection.Response
'Allow user to interactively select an edge
Dim response As Integer = 0
Dim user_data As System.IntPtr
Dim theCursor(2) As Double
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Dim curCursorView As Integer
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)
End Try
If Not theObject.Equals(Tag.Null) Then
theUfSession.Disp.SetHighlight(theObject, 0)
Else
theUfSession.Ui.SetCursorView(curCursorView)
Return Nothing
End If
Select Case response
Case UFConstants.UF_UI_BACK
Return Selection.Response.Back
Case UFConstants.UF_UI_OK
Return Selection.Response.Ok
Case UFConstants.UF_UI_OBJECT_SELECTED
Return Selection.Response.ObjectSelected
Case UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME
Return Selection.Response.ObjectSelectedByName
Case Else
Return Selection.Response.Cancel
End Select
End Function
Public Function init_proc_body(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer
'this function must have the same signature as UFUi.SelInitFnT Delegate
'setup mask to filter for edges or curves
Dim num_triples As Integer = 2
Dim 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
mask_triples(1).object_type = UFConstants.UF_solid_type
mask_triples(1).solid_type = UFConstants.UF_UI_SEL_FEATURE_CIRCULAR_EDGE
theUfSession.Ui.SetSelMask(select_, _
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
End Module
Re: Get Part From Hole Edge
Thanks for code expanded the selection function to allow circular edges to be selected but it working only in modeling and applies to edges, I need drafting curve in drafting module.
When you run my code in drafting and select threaded hole curve you will see part name, but when you run it one more time and select hole curve will be failed.
Anyway, do you know how to find owning component and feature name selected drafting curve?
Thanks
Marcin
re: part from hole edge
To effectively answer this question, we'll need to know what drafting view representation you are using. The possibilities (as of NX 9) are:
1) Exact
2) Exact (pre-NX 8.5)
3) Lightweight
4) Smart Lightweight
You can find the view representation type by going into the view settings and looking at configuration -> settings -> representation. The code posted previously was tested on the "Exact (pre-NX 8.5)" view type. From your results, I would guess you are using the "Exact" view type. The drafting curves are different for these view types and different functions must be used to process them.
If you are using the "Exact" view representation, you should look into the functions:
.AskDraftingCurveType
.AskDraftingCurveParents
These functions should help to get the information that you need.
If you are using the "Exact (pre-NX 8.5)" view representation type, you may find some useful code here:
http://nxjournaling.com/content/move-parts-list-callout-leader-location
especially in the "GetComponentOfBalloon" function.
re: part from hole edge
I checked and I am using "Exact" view type. I will try to find recomended by you functions and let you know back information.
Thanks
Marcin
Get Feature Name from selected drafting curve
I used recommended by you functions and it working great. I recived file name as I need. Thanks You very much. Below is code.
Could you help me how to get feature name seleced drafting curve. I tried with function
.Modl.AskObjectFeat
but there are working only in modeling not drafting module. When I will have holepackage feature name I try extract e.g. kind of thread, depth of thread, depth of drill etc. and put this information in dimension line.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module SelectDraftingEdge
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim theUI As UI = UI.GetUI
Sub Main()
Dim mySelViewTag As Tag = Tag.Null
Dim mySelEdgeTag As Tag = Nothing
Dim myEdgeCurve As DisplayableObject
lw.open()
If IsNothing(theSession.Parts.Work) Then
'active part required
lw.WriteLine(" no active part, exiting journal")
Return
End If
Dim currentApplication As Integer
theUfSession.UF.AskApplicationModule(currentApplication)
If Not currentApplication = UFConstants.UF_APP_DRAFTING Then
theUI.NXMessageBox.Show("Error !!!", NXMessageBox.DialogType.Error, "Journal will be working only in ""DRAFTING"" module")
Exit Sub
End If
Const undoMarkName As String = "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")
exit sub
End If
Dim myComponent As Assemblies.Component
Dim dwgObj As NXObject
' *************** Part Name of HOLE ********************
Dim CurveType As NXOpen.UF.UFDraw.DraftingCurveType
theUfSession.Draw.AskDraftingCurveType(mySelEdgeTag, CurveType)
lw.writeline("CurveType: " & CurveType.ToString)
Dim ParentCount As Integer
Dim Parent() As Tag
theUfSession.Draw.AskDraftingCurveParents(mySelEdgeTag, ParentCount, Parent)
lw.writeline("ParentCount: " & ParentCount)
lw.writeline("Parent: " & Parent(ParentCount-1))
dwgObj = Utilities.NXObjectManager.Get(Parent(ParentCount-1))
lw.WriteLine("used by: " & dwgObj.ToString)
myComponent = dwgObj.OwningComponent
lw.WriteLine(" File name: " & myComponent.DisplayName)
' ***********************************
lw.WriteLine(" selected object type: " & myEdgeCurve.GetType.ToString)
lw.writeline(" IsOccurrence: " & myEdgeCurve.IsOccurrence.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()
End Sub
Function UserSelectEdge(ByVal prompt As String, ByRef theView As Tag, ByRef theObject As Tag) As Selection.Response
'Allow user to interactively select an edge
Dim response As Integer = 0
Dim user_data As System.IntPtr
Dim theCursor(2) As Double
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Dim curCursorView As Integer
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)
End Try
If Not theObject.Equals(Tag.Null) Then
theUfSession.Disp.SetHighlight(theObject, 0)
Else
theUfSession.Ui.SetCursorView(curCursorView)
Return Nothing
End If
Select Case response
Case UFConstants.UF_UI_BACK
Return Selection.Response.Back
Case UFConstants.UF_UI_OK
Return Selection.Response.Ok
Case UFConstants.UF_UI_OBJECT_SELECTED
Return Selection.Response.ObjectSelected
Case UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME
Return Selection.Response.ObjectSelectedByName
Case Else
Return Selection.Response.Cancel
End Select
End Function
Public Function init_proc_body(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer
'this function must have the same signature as UFUi.SelInitFnT Delegate
'setup mask to filter for edges or curves
Dim num_triples As Integer = 2
Dim 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
mask_triples(1).object_type = UFConstants.UF_solid_type
mask_triples(1).solid_type = UFConstants.UF_UI_SEL_FEATURE_CIRCULAR_EDGE
theUfSession.Ui.SetSelMask(select_, _
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
End Module
Many thanks
Marcin
Get Feature Name from selected drafting curve
I introduced you in error because function
.Modl.AskObjectFeat (Tag object_tag, Tag feature_tag)
work in drafting but is needed correct object tag.
Tag "myEdgeCurve.Tag" in above code is not proper because shown value from DRAFTING, not from MODELING module.
Anybody know how to find right object_tag (selected curve tag) which will be correct for .Modl.AskObjectFeat function? Or maybe someone know simple way to find feature name selected curve in drafting?
Thanks
Marcin
NX10
re: feature from drafting curve
The following code additions are a bit rough, but should illustrate the basics.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module feature_from_dwg_curve
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim theUI As UI = ui.GetUI
Sub Main()
Dim mySelViewTag As Tag = Tag.Null
Dim mySelEdgeTag As Tag = Nothing
Dim myEdgeCurve As DisplayableObject
lw.open()
If IsNothing(theSession.Parts.Work) Then
'active part required
lw.WriteLine(" no active part, exiting journal")
Return
End If
Dim currentApplication As Integer
theUfSession.UF.AskApplicationModule(currentApplication)
If Not currentApplication = UFConstants.UF_APP_DRAFTING Then
theUI.NXMessageBox.Show("Error !!!", NXMessageBox.DialogType.Error, "Journal will be working only in ""DRAFTING"" module")
Exit Sub
End If
Const undoMarkName As String = "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")
Exit Sub
End If
Dim myComponent As Assemblies.Component
Dim dwgObj As Edge
' *************** Part Name of HOLE ********************
Dim CurveType As NXOpen.UF.UFDraw.DraftingCurveType
theUfSession.Draw.AskDraftingCurveType(mySelEdgeTag, CurveType)
lw.writeline("CurveType: " & CurveType.ToString)
Dim ParentCount As Integer
Dim Parent() As Tag
theUfSession.Draw.AskDraftingCurveParents(mySelEdgeTag, ParentCount, Parent)
lw.writeline("ParentCount: " & ParentCount)
lw.writeline("Parent: " & Parent(ParentCount - 1))
dwgObj = Utilities.NXObjectManager.Get(Parent(ParentCount - 1))
lw.WriteLine("used by: " & dwgObj.ToString)
myComponent = dwgObj.OwningComponent
Dim theEdgeFeats() As tag
theUfSession.modl.askedgefeats(dwgObj.tag, theEdgeFeats)
lw.writeline("feature count: " & theEdgeFeats.Length.ToString)
For Each featTag As Tag In theEdgeFeats
Dim someFeature As Features.Feature = Utilities.NXObjectManager.Get(featTag)
lw.WriteLine(" feature name: " & someFeature.GetFeatureName)
Next
lw.WriteLine(" File name: " & myComponent.DisplayName)
' ***********************************
lw.WriteLine(" selected object type: " & myEdgeCurve.GetType.ToString)
lw.writeline(" IsOccurrence: " & myEdgeCurve.IsOccurrence.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()
End Sub
Function UserSelectEdge(ByVal prompt As String, ByRef theView As Tag, ByRef theObject As Tag) As Selection.Response
'Allow user to interactively select an edge
Dim response As Integer = 0
Dim user_data As System.IntPtr
Dim theCursor(2) As Double
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Dim curCursorView As Integer
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)
End Try
If Not theObject.Equals(Tag.Null) Then
theUfSession.Disp.SetHighlight(theObject, 0)
Else
theUfSession.Ui.SetCursorView(curCursorView)
Return Nothing
End If
Select Case response
Case UFConstants.UF_UI_BACK
Return Selection.Response.Back
Case UFConstants.UF_UI_OK
Return Selection.Response.Ok
Case UFConstants.UF_UI_OBJECT_SELECTED
Return Selection.Response.ObjectSelected
Case UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME
Return Selection.Response.ObjectSelectedByName
Case Else
Return Selection.Response.Cancel
End Select
End Function
Public Function init_proc_body(ByVal select_ As IntPtr,
ByVal userdata As IntPtr) As Integer
'this function must have the same signature as UFUi.SelInitFnT Delegate
'setup mask to filter for edges or curves
Dim num_triples As Integer = 2
Dim 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
mask_triples(1).object_type = UFConstants.UF_solid_type
mask_triples(1).solid_type = UFConstants.UF_UI_SEL_FEATURE_CIRCULAR_EDGE
theUfSession.Ui.SetSelMask(select_,
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific,
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
End Module
re: feature from drafting curve
You are great!!! This is exactly what I need. Below is code where additionaly I added ".AskFaceFeats" function.
When I will be have completed code I share with him.
One more time many thanks.
Marcin
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module SelectDraftingEdge
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim theUI As UI = UI.GetUI
Sub Main()
Dim mySelViewTag As Tag = Tag.Null
Dim mySelEdgeTag As Tag = Nothing
Dim myEdgeCurve As DisplayableObject
lw.open()
If IsNothing(theSession.Parts.Work) Then
'active part required
lw.WriteLine(" no active part, exiting journal")
Return
End If
Dim currentApplication As Integer
theUfSession.UF.AskApplicationModule(currentApplication)
If Not currentApplication = UFConstants.UF_APP_DRAFTING Then
theUI.NXMessageBox.Show("Error !!!", NXMessageBox.DialogType.Error, "Journal will be working only in ""DRAFTING"" module")
Exit Sub
End If
Const undoMarkName As String = "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")
exit sub
End If
Dim myComponent As Assemblies.Component
Dim dwgObj As NXObject ' Edge
' *************** Part Name of HOLE ********************
Dim CurveType As NXOpen.UF.UFDraw.DraftingCurveType
theUfSession.Draw.AskDraftingCurveType(mySelEdgeTag, CurveType)
lw.writeline("CurveType: " & CurveType.ToString)
lw.writeline("CurveType: " & CurveType)
Dim ParentCount As Integer
Dim Parent() As Tag
Dim ParentTag As Tag
theUfSession.Draw.AskDraftingCurveParents(mySelEdgeTag, ParentCount, Parent)
lw.writeline("ParentCount: " & ParentCount)
ParentTag = Parent(ParentCount-1)
lw.writeline("Parent: " & ParentTag)
dwgObj = Utilities.NXObjectManager.Get(Parent(ParentCount-1))
lw.WriteLine("used by: " & dwgObj.ToString)
lw.writeline(dwgObj.Tag)
myComponent = dwgObj.OwningComponent
If Not CurveType = 3 then
Dim theEdgeFeats() As tag
theUfSession.modl.AskEdgeFeats(dwgObj.tag, theEdgeFeats)
'lw.writeline("feature count: " & theEdgeFeats.Length.ToString)
For Each featTag As Tag In theEdgeFeats
Dim someFeature As Features.Feature = Utilities.NXObjectManager.Get(featTag)
If someFeature.FeatureType = "HOLE PACKAGE" Then
Dim theHolePackageBuilder As Features.HolePackageBuilder = displayPart.Features.CreateHolePackageBuilder(someFeature)
If theHolePackageBuilder.Type = Features.HolePackageBuilder.Types.GeneralHole Then
lw.WriteLine(" feature name: " & someFeature.GetFeatureName)
End if
End If
Next
Else
Dim theFaceFeats() As tag
theUfSession.modl.AskFaceFeats(dwgObj.tag, theFaceFeats)
'lw.writeline("feature count: " & theFaceFeats.Length.ToString)
For Each featTag As Tag In theFaceFeats
Dim someFeature As Features.Feature = Utilities.NXObjectManager.Get(featTag)
If someFeature.FeatureType = "HOLE PACKAGE" Then
Dim theHolePackageBuilder As Features.HolePackageBuilder = displayPart.Features.CreateHolePackageBuilder(someFeature)
If theHolePackageBuilder.Type = Features.HolePackageBuilder.Types.ThreadedHole Then
lw.WriteLine(" feature name: " & someFeature.GetFeatureName)
End if
End If
Next
End If
lw.WriteLine(" File name: " & myComponent.DisplayName)
' ***********************************
lw.WriteLine(" selected object type: " & myEdgeCurve.GetType.ToString)
lw.writeline(" IsOccurrence: " & myEdgeCurve.IsOccurrence.tostring)
lw.writeline(" Tag: " & myEdgeCurve.Tag)
lw.writeline(" Tag Owning Part: " & myEdgeCurve.OwningPart.Tag)
lw.writeline("mySelEdgeTag: " & mySelEdgeTag)
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()
End Sub
Function UserSelectEdge(ByVal prompt As String, ByRef theView As Tag, ByRef theObject As Tag) As Selection.Response
'Allow user to interactively select an edge
Dim response As Integer = 0
Dim user_data As System.IntPtr
Dim theCursor(2) As Double
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Dim curCursorView As Integer
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)
End Try
If Not theObject.Equals(Tag.Null) Then
theUfSession.Disp.SetHighlight(theObject, 0)
Else
theUfSession.Ui.SetCursorView(curCursorView)
Return Nothing
End If
Select Case response
Case UFConstants.UF_UI_BACK
Return Selection.Response.Back
Case UFConstants.UF_UI_OK
Return Selection.Response.Ok
Case UFConstants.UF_UI_OBJECT_SELECTED
Return Selection.Response.ObjectSelected
Case UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME
Return Selection.Response.ObjectSelectedByName
Case Else
Return Selection.Response.Cancel
End Select
End Function
Public Function init_proc_body(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer
'this function must have the same signature as UFUi.SelInitFnT Delegate
'setup mask to filter for edges or curves
Dim num_triples As Integer = 2
Dim 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
mask_triples(1).object_type = UFConstants.UF_solid_type
mask_triples(1).solid_type = UFConstants.UF_UI_SEL_FEATURE_CIRCULAR_EDGE
theUfSession.Ui.SetSelMask(select_, _
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
End Module