Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NXJournal - Trying to adapt a journal 1

Status
Not open for further replies.

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


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.
 
Replies continue below

Recommended for you

Try this one.

Code:
'NXJournaling.com
'September 1, 2021
'Select points with color of 60, 66, or 75 and delete them.
'[URL unfurl="true"]https://www.eng-tips.com/viewthread.cfm?qid=486672[/URL]


Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module2

    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 = "0f76ef7a-cc4e-4e34-8658-ee1a9f0e974c"
        theSession.LogFile.WriteLine("NXJID: " & nxjID)

        lw.Open()
        Dim pointsToDelete As New List(Of Point)

        If SelectPointsByColor(pointsToDelete) = Selection.Response.Cancel Then
            Return
        End If

        theSession.UpdateManager.ClearErrorList()

        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.AddToDeleteList(pointsToDelete.ToArray)

        Dim nErrs2 As Integer
        nErrs2 = theSession.UpdateManager.DoUpdate(markId1)

        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

www.nxjournaling.com
 
Thanks Cowski

This is almost perfect. THe only problem is if there are components with points, even though it wont delete them, it still selects them. Which would not be a problem except that after it is done, those points that were part of component stay highlighted.

Its frustrating because I just recently saw a few examples of how to change a selection routing from workpart to all assembly. I figured I would be able to use that reverse it to workpart only. Except now I cant find those examples anywhere. lol When I was looking for something else, I found them a few times. When I actually look for that, I cant find it. 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.
 
This version should turn off the highlighting (not tested).
Code:
'NXJournaling.com
'September 1, 2021
'Select points with color of 60, 66, or 75 and delete them.
'[URL unfurl="true"]https://www.eng-tips.com/viewthread.cfm?qid=486672[/URL]


Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module2

    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 = "0f76ef7a-cc4e-4e34-8658-ee1a9f0e974c"
        theSession.LogFile.WriteLine("NXJID: " & nxjID)

        lw.Open()
        Dim pointsToDelete As New List(Of Point)

        If SelectPointsByColor(pointsToDelete) = Selection.Response.Cancel Then
            Return
        End If

        For Each tempPoint As Point In pointsToDelete
            theUfSession.Disp.SetHighlight(tempPoint.Tag, 0)
        Next

        theSession.UpdateManager.ClearErrorList()

        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.AddToDeleteList(pointsToDelete.ToArray)

        Dim nErrs2 As Integer
        nErrs2 = theSession.UpdateManager.DoUpdate(markId1)

        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

If you want to limit the selection to the work part, find the following code (in the select points by color function):
Code:
theUfSession.Ui.SelectWithClassDialog("Select: ", "Select Points",
    UFConstants.[highlight #FCE94F]UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY[/highlight], AddressOf Mask1,
    user_data, response, selCount, selObj)

And change it to:
Code:
theUfSession.Ui.SelectWithClassDialog("Select: ", "Select Points",
    UFConstants.[highlight #FCE94F]UF_UI_SEL_SCOPE_WORK_PART[/highlight], AddressOf Mask1,
    user_data, response, selCount, selObj)

www.nxjournaling.com
 
Perfect. I like this because it allows me to have both code with one commented out for future reference.

Thank you so much. [bigsmile]


Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor