Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX9 - Journal Code Help Needed.... again. :o) 2

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
958
When in drafting, there seems to be some who like to see the borders around the views and some who don't. I thought it would be a good idea if I created a button to toggle the view borders on and off. I can record a journal to turn it on and one to turn it off, but I was wondering if someone could show me the way to use the "IF" correctly so one journal will turn it on or off depending on what the setting already is?

Just to make it clear, the same file will often be worked on by different people. That is why this is any kind of problem. Also, I find myself now working on something that I am constantly going back and forth turning the borders on and off.
 
Replies continue below

Recommended for you

No "If" is necessary.

Code:
Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "toggle drafting view borders"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim preferencesBuilder1 As Drafting.PreferencesBuilder
        preferencesBuilder1 = workPart.SettingsManager.CreatePreferencesBuilder()

        preferencesBuilder1.ViewWorkflow.DisplayBorders = Not preferencesBuilder1.ViewWorkflow.DisplayBorders

        Dim nXObject1 As NXObject
        nXObject1 = preferencesBuilder1.Commit()

        preferencesBuilder1.Destroy()

        lw.Close()

    End Sub


    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 awesome. I didn't know there was a toggle in code. Im gonna have to study this some to see how I get it to work for other things. lol
 
The code above works because the .DisplayBorders value is a boolean (true/false). The Not operation simply flips the value.

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor