Kenja824
Automotive
- Nov 5, 2014
- 949
Cowski, you recently made this journal for me where the user can only select points with specific colors and it moves them to layer 230.
I recorded a journal where points are deleted and have tried to adapt this one to do that. Same selection routine, but it deletes the points instead of moving them to another layer. This is to delete points created by Wave Link Geometry.
I have commented out lines that I replaced from the recorded journal and have tried at make the necessary adjustments. I got it to where it no longer gives me any errors but it isnt working right. The selection routine works right, but then when you hit OK, nothing happens. It never actually deletes the points.
There is an area where these two lines appear....
'theSession.Parts.Display.Layers.MoveDisplayableObjects(230, pointsToMove.ToArray)
theSession.UpdateManager.ClearErrorList() '************************
The top line I commented out and the bottom one I added from the recorded version. (The row of asterisks were only to make it easy to find) I cannot help but think that the top line needs to stay but just needs to be written different. My guess is that this line is what ties it all together so it knows to delete what is selected?
Am I even close? I am hoping I get at least a C+ for effort on this. lol
Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.
I recorded a journal where points are deleted and have tried to adapt this one to do that. Same selection routine, but it deletes the points instead of moving them to another layer. This is to delete points created by Wave Link Geometry.
I have commented out lines that I replaced from the recorded journal and have tried at make the necessary adjustments. I got it to where it no longer gives me any errors but it isnt working right. The selection routine works right, but then when you hit OK, nothing happens. It never actually deletes the points.
There is an area where these two lines appear....
'theSession.Parts.Display.Layers.MoveDisplayableObjects(230, pointsToMove.ToArray)
theSession.UpdateManager.ClearErrorList() '************************
The top line I commented out and the bottom one I added from the recorded version. (The row of asterisks were only to make it easy to find) I cannot help but think that the top line needs to stay but just needs to be written different. My guess is that this line is what ties it all together so it knows to delete what is selected?
Am I even close? I am hoping I get at least a C+ for effort on this. lol
Code:
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, "Delete Points")
Const nxjID As String = "b256cb5e-d18c-47cc-a7c4-798f5575758a"
theSession.LogFile.WriteLine("NXJID: " & nxjID)
lw.Open()
' Dim pointsToMove As New List(Of Point)
Dim AddObjectsToDelete As New List(Of Point)
'If SelectPointsByColor(pointsToMove) = Selection.Response.Cancel Then
' Return
'End If
If SelectPointsByColor(AddObjectsToDelete) = Selection.Response.Cancel Then
Return
End If
'theSession.Parts.Display.Layers.MoveDisplayableObjects(230, pointsToMove.ToArray)
theSession.UpdateManager.ClearErrorList() '************************
Dim objects1(0) As NXOpen.TaggedObject
' Dim point1 As NXOpen.Point = CType(workPart.Points.FindObject("HANDLE R-4242"), NXOpen.Point)
' objects1(0) = point1
Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.AddObjectsToDeleteList(objects1)
Dim id1 As NXOpen.Session.UndoMarkId = Nothing
id1 = theSession.NewestVisibleUndoMark
Dim nErrs2 As Integer = Nothing
nErrs2 = theSession.UpdateManager.DoUpdate(id1)
theSession.DeleteUndoMark(markId1, Nothing)
'For Each tempPoint As Point In pointsToMove
' theUfSession.Disp.SetHighlight(tempPoint.Tag, 0)
'Next
For Each tempPoint As Point In AddObjectsToDelete
theUfSession.Disp.SetHighlight(tempPoint.Tag, 0)
Next
lw.Close()
End Sub
Public Function SelectPointsByColor(ByRef thePoints As List(Of Point)) 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 Points",
UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, 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 selPoint As Point = Utilities.NXObjectManager.Get(tempTag)
thePoints.Add(selPoint)
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_point_type
.solid_type = UFConstants.UF_point_subtype
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 Point currently being considered for selection
Dim tempPoint As Point = Utilities.NXObjectManager.Get(_object)
'if the color is 60, 66, or 75 allow selection
If tempPoint.Color = 60 Then
Return UFConstants.UF_UI_SEL_ACCEPT
End If
If tempPoint.Color = 66 Then
Return UFConstants.UF_UI_SEL_ACCEPT
End If
If tempPoint.Color = 75 Then
Return UFConstants.UF_UI_SEL_ACCEPT
End If
Return UFConstants.UF_UI_SEL_REJECT
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
Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.