Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Journaling to toogle LineWidth Display in Modeling or Drafting depending on current Application-Mode 1

Status
Not open for further replies.

MEichWey

Industrial
Apr 16, 2014
39
Hello all,

I have written a small Journal to toggle the linewidth Display in drafting-mode or in modeling-mode with only one button. In this case, the tool has to be determine if we are in modeling-mode or in drafting mode, cause we have two variables - one for each of the applications:
workPart.Preferences.ColorSettingVisualization.ShowWidths -> for drafting-mode / -sheet
workPart.Preferences.LineVisualization.ShowWidths -> for modeling-mode / view

I have created the following code, witch is asking the display state (view type). I found it here. But it doesn´t work correct.
If I have open a specification (from Teamcenter) with a drawing sheet and run the tool, it works. But if I switch then to Modeling nothing happens, because the viewType is still 2, which means "drafting view". But I see the model-view. If I change the display part to the master-model, then the tool works right in modeling-mode.

Is there any other possibility to get or ask the current application-mode?

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module ToggleThickness

    Dim theSession As Session = Session.GetSession()
    Dim theUFSession As UFSession = UFSession.GetUFSession
    Dim theUI As UI = UI.GetUI
    Dim workPart As Part = theSession.Parts.Work
    Dim displayPart As Part = theSession.Parts.Display
    Dim lw As ListingWindow = theSession.ListingWindow
	

    Sub Main()
	lw.Open()
	
		Dim viewType As Integer = 0
		'1 = modeling view
		'2 = drawing view
		'other = error
		theUFSession.Draw.AskDisplayState(viewType)
		lw.WriteLine(viewType)
	
		if viewType = 2 then
			'Toggles LineWidth-Display on Drawing Sheet in Drafting Mode
			Dim ShowWDra As Boolean = workPart.Preferences.ColorSettingVisualization.ShowWidths
			workPart.Preferences.ColorSettingVisualization.ShowWidths = Not ShowWDra
		
		else
			'Toggles LineWidth-Display in Modeling Mode and View
			Dim ShowWMod As Boolean = workPart.Preferences.LineVisualization.ShowWidths
			workPart.Preferences.LineVisualization.ShowWidths = Not ShowWMod
		
		end if
	lw.Close()	
    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
	
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function				

End Module

I also tried to use "UI.GetUI.MenuBarManager.ApplicationSwitchRequest("Application")". But I can only change the application with it, not asking the current state.

Michael
 
Replies continue below

Recommended for you

The .AskDisplayState method only works within the drafting application (by design). It does not tell you what application is running, it only tells you if a drawing sheet is displayed or not. If you switch to the drafting application normally a drawing sheet is displayed (if one exists), you can turn the drawing sheet off to view the model without leaving the drafting application. As long as you are in the drafting application, the .AskDisplayState method will tell you if a drawing sheet is displayed or a model view is displayed.

If you need to know what application NX is currently in, use the .AskApplicationModule method.

www.nxjournaling.com
 
Hi Cowski,

yes, this works great! Here is the new complete Code:

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module ToggleThickness

    Dim theSession As Session = Session.GetSession()
	Dim theUFSession As UFSession = UFSession.GetUFSession()
	Dim theUI As UI = UI.GetUI
	Dim workPart As Part = theSession.Parts.Work
	Dim displayPart As Part = theSession.Parts.Display

    Sub Main()
	
		Dim module_id As Integer = 0
		theUFSession.UF.AskApplicationModule(module_id)
		
		if module_id = UFConstants.UF_APP_DRAFTING then
			'Toggles LineWidth-Display on Drawing Sheet in Drafting Mode
			Dim ShowWDra As Boolean = workPart.Preferences.ColorSettingVisualization.ShowWidths
			workPart.Preferences.ColorSettingVisualization.ShowWidths = Not ShowWDra
		
		else
			'Toggles LineWidth-Display in Modeling Mode and View
			Dim ShowWMod As Boolean = workPart.Preferences.LineVisualization.ShowWidths
			workPart.Preferences.LineVisualization.ShowWidths = Not ShowWMod
		
		end if

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
	
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function				

End Module

Thank you!
Michael
 
I'm interested in this. How do I copy the code with carriage returns?
Thanks
 
Open a plain text editor such as notepad (do not use MS Word or Wordpad), then copy and paste the journal code. Save the file to a convenient location changing the file extension to .vb. In NX, go to Tools -> journal -> play..., browse to the file and press "Run".

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

Part and Inventory Search

Sponsor