Change to monochrome if in drafting application

Hi,

I'm trying to create an if statement that will do the following:

-----------------------------

If the application is currently set to drafting and "monochrome view is not active" then

switch to monochrome

run some code

switch back to "not monochrome"

else

run a different code

end if
-----------------------------

I don't know how to check what the current application is or how to switch on and off monochrome view.
If anybody has any ideas or could point me in the right direction it would be very much appreciated.

Thanks!

The code below should get you started:

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

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

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

Const undoMarkName As String = "monochrome"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim currentApplication As Integer
theUfSession.UF.AskApplicationModule(currentApplication)

Select Case currentApplication
Case Is = UFConstants.UF_APP_GATEWAY
'code for gateway app
lw.WriteLine("now in Gateway")
Case Is = UFConstants.UF_APP_MODELING
'code for modeling
lw.WriteLine("now in Modeling")
Case Is = UFConstants.UF_APP_DRAFTING
lw.WriteLine("now in Drafting")
Dim curMonoDisp As Boolean = workPart.Preferences.ColorSettingVisualization.MonochromeDisplay
'change to monochrome
workPart.Preferences.ColorSettingVisualization.MonochromeDisplay = True
'do other stuff
MsgBox("display is now monochrome")
'do other stuff

workPart.Preferences.ColorSettingVisualization.MonochromeDisplay = curMonoDisp
MsgBox("display back to previous setting")

'defined constants for other applications can be found in
'{NX install directory}\UGOPEN\uf.h
Case Else
lw.WriteLine("application not currently handled")

End Select

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

Thanks a lot! This looks perfect and I think it will work well for the rest of my code.

BR

Stian LA