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!

Journal only works for one note? 1

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
I have merged a couple different journals I have. I want it to let the user select some notes. Often this will be done by windowing around a group of notes. Then it will change their font and other settings.

However, I only got it to the point where if I select one note it works. If I window around multiple notes, it only changes one of them. Can someone please help me make it so it makes the changes to all the notes that are selected?


Code:
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 workPart As NXOpen.Part = theSession.Parts.Work

    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Mirror Note")
        theSession.SetUndoMarkName(markId1, "Class Selection Dialog") 'ADDED*********

        Const nxjID As String = "b4310398-97e3-4726-9b7a-2a998d9da13b"
        theSession.LogFile.WriteLine("NXJID: " & nxjID)

        lw.Open()

        Dim notesAndLabels As New List(Of Annotations.NoteBase)
        Dim num_obj As Integer = 0
        Dim objtags As Tag() = Nothing
        theUfSession.Ui.AskGlobalSelObjectList(num_obj, objtags)

        If num_obj > 0 Then
            'process preselected objects
            For Each temp As Tag In objtags
                Dim tempTaggedObj As TaggedObject = theSession.GetObjectManager.GetTaggedObject(temp)
                If TypeOf (tempTaggedObj) Is NXOpen.Annotations.Note OrElse TypeOf (tempTaggedObj) Is NXOpen.Annotations.Label Then
                    notesAndLabels.Add(tempTaggedObj)
                End If
            Next
        End If

        If notesAndLabels.Count = 0 Then
            'no preselected objects, prompt for selection
            If SelectNotesLabels("Select Notes and/or Labels", notesAndLabels) = Selection.Response.Cancel Then
                'user pressed cancel
                Return
            End If
        End If


        Dim objects1(0) As NXOpen.DisplayableObject

        objects1(0) = notesAndLabels(0)
        Dim editSettingsBuilder1 As NXOpen.Annotations.EditSettingsBuilder = Nothing
        editSettingsBuilder1 = workPart.SettingsManager.CreateAnnotationEditSettingsBuilder(objects1)


        Dim editsettingsbuilders1(0) As NXOpen.Drafting.BaseEditSettingsBuilder
        editsettingsbuilders1(0) = editSettingsBuilder1
        workPart.SettingsManager.ProcessForMultipleObjectsSettings(editsettingsbuilders1)

        Dim fontIndex1 As Integer = Nothing
        fontIndex1 = workPart.Fonts.AddFont("Arial Unicode MS", NXOpen.FontCollection.Type.Standard)

        editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextFont = 1
        editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextLineWidth = NXOpen.Annotations.LineWidth.Thin
        editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextSize = 2.0
        editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextAspectRatio = 1.0
        editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextLineSpaceFactor = 0.5


        Dim nXObject1 As NXOpen.NXObject = Nothing
        nXObject1 = editSettingsBuilder1.Commit()

        editSettingsBuilder1.Destroy()



        lw.Close()

    End Sub

    Function SelectNotesLabels(ByVal prompt As String, ByRef selList As List(Of Annotations.NoteBase)) As Selection.Response

        selList.Clear()
        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select Notes and/or Labels"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(1) As Selection.MaskTriple
        Dim selObj() As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_drafting_entity_type
            .Subtype = UFConstants.UF_draft_note_subtype
        End With

        With selectionMask_array(1)
            .Type = UFConstants.UF_drafting_entity_type
            .Subtype = UFConstants.UF_draft_label_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt,
        title, scope, selAction,
        includeFeatures, keepHighlighted, selectionMask_array, selObj)
        If resp = Selection.Response.Ok Then
            For Each temp As Annotations.NoteBase In selObj
                selList.Add(temp)
            Next
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        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

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:
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 workPart As NXOpen.Part = theSession.Parts.Work

    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Mirror Note")
        theSession.SetUndoMarkName(markId1, "Class Selection Dialog") 'ADDED*********

        Const nxjID As String = "611e24cc-577f-4d82-87b7-379db54b06c2"
        theSession.LogFile.WriteLine("NXJID: " & nxjID)

        lw.Open()

        Dim notesAndLabels As New List(Of Annotations.NoteBase)
        Dim num_obj As Integer = 0
        Dim objtags As Tag() = Nothing
        theUfSession.Ui.AskGlobalSelObjectList(num_obj, objtags)

        If num_obj > 0 Then
            'process preselected objects
            For Each temp As Tag In objtags
                Dim tempTaggedObj As TaggedObject = theSession.GetObjectManager.GetTaggedObject(temp)
                If TypeOf (tempTaggedObj) Is NXOpen.Annotations.Note OrElse TypeOf (tempTaggedObj) Is NXOpen.Annotations.Label Then
                    notesAndLabels.Add(tempTaggedObj)
                End If
            Next
        End If

        If notesAndLabels.Count = 0 Then
            'no preselected objects, prompt for selection
            If SelectNotesLabels("Select Notes and/or Labels", notesAndLabels) = Selection.Response.Cancel Then
                'user pressed cancel
                Return
            End If
        End If

        For each tempNote as Annotations.NoteBase in notesAndLabels
		    
            Dim editSettingsBuilder1 As NXOpen.Annotations.EditSettingsBuilder = Nothing
            editSettingsBuilder1 = workPart.SettingsManager.CreateAnnotationEditSettingsBuilder({tempNote})
		    
		    
            Dim editsettingsbuilders1(0) As NXOpen.Drafting.BaseEditSettingsBuilder
            editsettingsbuilders1(0) = editSettingsBuilder1
            workPart.SettingsManager.ProcessForMultipleObjectsSettings(editsettingsbuilders1)
		    
            Dim fontIndex1 As Integer = Nothing
            fontIndex1 = workPart.Fonts.AddFont("Arial Unicode MS", NXOpen.FontCollection.Type.Standard)
		    
            editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextFont = 1
            editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextLineWidth = NXOpen.Annotations.LineWidth.Thin
            editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextSize = 2.0
            editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextAspectRatio = 1.0
            editSettingsBuilder1.AnnotationStyle.LetteringStyle.GeneralTextLineSpaceFactor = 0.5
		    
		    
            Dim nXObject1 As NXOpen.NXObject = Nothing
            nXObject1 = editSettingsBuilder1.Commit()
		    
            editSettingsBuilder1.Destroy()
		    
        Next


        lw.Close()

    End Sub

    Function SelectNotesLabels(ByVal prompt As String, ByRef selList As List(Of Annotations.NoteBase)) As Selection.Response

        selList.Clear()
        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select Notes and/or Labels"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(1) As Selection.MaskTriple
        Dim selObj() As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_drafting_entity_type
            .Subtype = UFConstants.UF_draft_note_subtype
        End With

        With selectionMask_array(1)
            .Type = UFConstants.UF_drafting_entity_type
            .Subtype = UFConstants.UF_draft_label_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt,
        title, scope, selAction,
        includeFeatures, keepHighlighted, selectionMask_array, selObj)
        If resp = Selection.Response.Ok Then
            For Each temp As Annotations.NoteBase In selObj
                selList.Add(temp)
            Next
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        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

www.nxjournaling.com
 
Awesome Cowski

Thank you.

I took a little time to compare them. Looks like I had a couple lines that were not needed and you added the For Each code of line with a Next after that section of code. Cant say I fully understand how it all works, but I can kind of see it. lol Maybe by the time I am 85 and considering retirement, I will finally get a grasp of this stuff. 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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor