Hello at all,
I have a problem with my SelectObjects function. I want to select various drilling holes, but if I the distance between the centre of the holes are smaller than a given a range, I want to get a warning. Important is that we select the circle of the holes and not the centre.
For example:
Hole1 have to be minimum 100 mm away from Hole2
Hole2 have to be minimum 100 mm away from Hole3
But it isn't important which distance is between Hole1 and Hole3
I didn't found anything by now for putting conditions in the SelectObjects function and also having a problem in getting the distance between two centres by only choosing the holes.
If SelectObjects("Select holes",
mySelectedObjects) = Selection.Response.Ok Then
'...
Function SelectObjects(prompt As String,
ByRef selObj As NXObject()) As Selection.Response
Dim theUI As UI = UI.GetUI
'only choose edges
Dim typeArray() As Selection.SelectionType =
{Selection.SelectionType.Edges}
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(
prompt, "Selection",
Selection.SelectionScope.AnyInAssembly,
False, typeArray, selObj)
If resp = Selection.Response.ObjectSelected Or
resp = Selection.Response.ObjectSelectedByName Or
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Thanks already for any help
re: select holes
It sounds like you want to select circular edges where the center of each circular edge is a minimum of 100 mm away from the previously selected edge. Is this correct?
If so, one way to do this would be with the .SelectWithClassDialog method. This method would allow you to do some processing (such as distance calculations) while the user is selecting objects. I don't think there is a similar example currently on this site, but if my understanding of your problem is correct, I'll find/create an example as time permits.
Centres
Yes the centres have to be 100 mm away from each other. The thing is that only the two followed circles have to be messed.
If the centre of circle 1 is over 100 mm away from the centre of circle 2, circle 1 stays marked an by choosing circle3 you have to check the distance from 2 to 3 and so on.
It would really help me if you are having something in this direction.
Thank you
re: select circular edges with minimum distance constraint
The code below will limit your selection to circular edges; each selected edge must be 100 distance units from the previously selected edge. The filter section of the code will check the distance and disallow selection of any edge that does not meet the distance requirement.
Caveats: the code was written for and tested on a metric part; it does not check for metric/imperial part units. If run on a part that uses imperial units it will probably limit selection to edges 100 inches away from the last selection. Also, in this demo code, the selected edges will be left in a 'highlighted' state. Run a part cleanup with the 'remove extraneous highlighting' option to turn it off.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")
lw.Open()
Dim circularEdges As New List(Of Edge)
If SelectCircularEdges(circularEdges) = Selection.Response.Cancel Then
Return
End If
For Each temp As Edge In circularEdges
lw.WriteLine("edge tag: " & temp.Tag.ToString)
Next
lw.Close()
End Sub
Public Function SelectCircularEdges(ByRef theEdges As List(Of Edge)) As Selection.Response
Dim response As Integer = 0
Dim user_data As System.IntPtr
Dim selCount As Integer
Dim selObj() As Tag = Nothing
Dim myCursor(2) As Double
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Dim curCursorView As Integer
theUfSession.Ui.AskCursorView(curCursorView)
Try
theUfSession.Ui.SetCursorView(0)
theUfSession.Ui.SelectWithClassDialog("Select: ", "Select circular edges",
UFConstants.UF_UI_SEL_SCOPE_WORK_PART, AddressOf Mask1,
user_data, response, selCount, selObj)
Finally
theUfSession.Ui.SetCursorView(curCursorView)
theUfSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
End Try
If response = UFConstants.UF_UI_BACK Or response = UFConstants.UF_UI_CANCEL Then
Return Selection.Response.Cancel
Else
If Not selObj.Equals(Tag.Null) Then
'the SelectWithClassDialog method returns an array of tags,
'return the objects from the given tags
For Each tempTag As Tag In selObj
Dim circularEdge As Edge = Utilities.NXObjectManager.Get(tempTag)
theEdges.Add(circularEdge)
Next
Else
'selObj = Tag.Null
'should not happen
Return Selection.Response.Cancel
End If
Return Selection.Response.Ok
End If
End Function
Public Function Mask1(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 circular edges
Dim num_triples As Integer = 1
Dim mask_triples(num_triples - 1) As UFUi.Mask
With mask_triples(0)
.object_type = UFConstants.UF_solid_type
.solid_type = UFConstants.UF_UI_SEL_FEATURE_CIRCULAR_EDGE
End With
theUfSession.Ui.SetSelMask(select_,
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific,
num_triples, mask_triples)
theUfSession.Ui.SetSelProcs(select_, AddressOf Filter1, Nothing, userdata)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
Public Function Filter1(ByVal _object As Tag,
ByVal type As Integer(),
ByVal user_data As IntPtr,
ByVal select_ As IntPtr) As Integer
'type and user_data are unused, but this function must have
'the same signature as UFUi.SelFilterFnT Delegate
'get the edge currently being considered for selection
Dim tempEdge As Edge = Utilities.NXObjectManager.Get(_object)
Dim pt1 As Point = theSession.Parts.Work.Points.CreatePoint(tempEdge, SmartObject.UpdateOption.WithinModeling)
'get the previously selected edges (if any)
Dim count As Integer
Dim selTags() As Tag = Nothing
theUfSession.Ui.AskSelObjectList(select_, count, selTags)
If count = 0 Then
'no other edges selected, allow this selection
Return UFConstants.UF_UI_SEL_ACCEPT
End If
'get the last selected edge
Dim lastEdge As Edge = Utilities.NXObjectManager.Get(selTags(count - 1))
'get center point of last selected edge
Dim pt2 As Point = theSession.Parts.Work.Points.CreatePoint(lastEdge, SmartObject.UpdateOption.WithinModeling)
'measure distance between center points of last selected edge and current edge being considered
Dim minDist As Double
Dim outPt1(2) As Double
Dim outPt2(2) As Double
theUfSession.Modl.AskMinimumDist(pt1.Tag, pt2.Tag, 0, Nothing, 0, Nothing, minDist, outPt1, outPt2)
'if distance is greater or equal to 100, accept the current selection
If minDist >= 100 Then
Return UFConstants.UF_UI_SEL_ACCEPT
Else
Return UFConstants.UF_UI_SEL_REJECT
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module