Submitted by bhavik231187 on Sun, 04/24/2016 - 19:56
Forums:
Hello guys,
I am creating drawing template and title block through .dll and after completing the process it is remain in Modeling workbench.
After that I want to use some parameter of the drafting but due to Modeling workbench I am not able to use that.
For switching I am using below line code but it is not working.
UI.GetUI.MenuBarManager.ApplicationSwitchRequest("UG_APP_DRAFTING")
Can anyone please help me ?
re: switch application
It is possible to turn off the sheet display when you are in the drafting application; when you do so, it appears that you are in the modeling application. I'd first check to make sure that you are in the modeling application after the call to ApplicationSwitchRequest. The ApplicationSwitchRequest method won't change anything until your code exits. If your code exits without error and you are sure that you are still in the modeling application, you may want to contact GTAC so they can investigate.
Switch Application
I am using ApplicationSwitchRequest method in the end.
As you mentioned, i checked for error also but I am not getting any error in the process.
When we go to Start option to change workbench in that,I am getting modeling and drafting both the workbench.
So I am not sure is it ok or not.
One more thing I have created .dll for this and I am using it through GUI.
Bhavik S.
re: switch application
Below is some sample code to switch between modeling and drafting; it was tested on NX 9. It should work on NX 8 or above.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module2
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUI As UI = UI.GetUI
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
lw.Open()
Dim workPart As Part = theSession.Parts.Work
'See the APPLICATION_BUTTON's defined in the ug_main.men file
'UG_APP_GATEWAY
'UG_APP_MODELING
'UG_APP_STUDIO
'UG_APP_DRAFTING
'UG_APP_MANUFACTURING
'UG_APP_SFEM
'UG_APP_DESFEM
'UG_APP_MECHANISMS
'UG_APP_MECHATRONICS
'UG_APP_SHEETMETAL
'UG_APP_PCB_DESIGN
'UG_APP_ROUTING
'etc.
'toggle between modeling and drafting
'if user is in module other than modeling or drafting, do nothing
Dim currentModuleId As Integer
theUfSession.UF.AskApplicationModule(currentModuleId)
Select Case currentModuleId
Case Is = UFConstants.UF_APP_MODELING
lw.WriteLine("journal started from modeling application, switching to drafting")
theUI.MenuBarManager.ApplicationSwitchRequest("UG_APP_DRAFTING")
Case Is = UFConstants.UF_APP_DRAFTING
lw.WriteLine("journal started from drafting application, switching to modeling")
theUI.MenuBarManager.ApplicationSwitchRequest("UG_APP_MODELING")
Case Else
lw.WriteLine("journal started from an application other than modeling or drafting")
'take no action
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
Switch Application
Hi,
The code is very helpful and it is giving me the correct message after running it.
But still it is not switching between the applications. It stays on the current workbench only.
Bhavik S.
re: drawing display
Below is a modified version of the previous code. It will check the display state of the drawing sheet; if there is a drawing to display, it will make sure it is turned on before switching to the drafting application.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module2
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUI As UI = UI.GetUI
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
lw.Open()
Dim workPart As Part = theSession.Parts.Work
'See the APPLICATION_BUTTON's defined in the ug_main.men file
'UG_APP_GATEWAY
'UG_APP_MODELING
'UG_APP_STUDIO
'UG_APP_DRAFTING
'UG_APP_MANUFACTURING
'UG_APP_SFEM
'UG_APP_DESFEM
'UG_APP_MECHANISMS
'UG_APP_MECHATRONICS
'UG_APP_SHEETMETAL
'UG_APP_PCB_DESIGN
'UG_APP_ROUTING
'etc.
'toggle between modeling and drafting
'if user is in module other than modeling or drafting, do nothing
Dim currentModuleId As Integer
theUfSession.UF.AskApplicationModule(currentModuleId)
Dim sheetCount As Integer = workPart.DrawingSheets.ToArray.Length
lw.WriteLine("work part contains " & sheetCount.ToString & " drawing sheets")
Dim dispState As Integer
theUfSession.Draw.AskDisplayState(dispState)
If dispState = 1 Then
lw.WriteLine("no drawing sheet currently displayed in drafting")
If sheetCount = 0 Then
lw.WriteLine("no drawing sheet to display")
Else
lw.WriteLine("activating display of drafting sheet")
theUfSession.Draw.SetDisplayState(2)
End If
Else
lw.WriteLine("drawing sheet displayed in drafting")
End If
Select Case currentModuleId
Case Is = UFConstants.UF_APP_MODELING
lw.WriteLine("journal started from modeling application, switching to drafting")
theUI.MenuBarManager.ApplicationSwitchRequest("UG_APP_DRAFTING")
Case Is = UFConstants.UF_APP_DRAFTING
lw.WriteLine("journal started from drafting application, switching to modeling")
theUI.MenuBarManager.ApplicationSwitchRequest("UG_APP_MODELING")
Case Else
lw.WriteLine("journal started from an application other than modeling or drafting")
'take no action
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
Switch Application
Hi,
Thanks for the updated code.
It is working as expected.
Bhavik S.
re: switch application
If this code works, that means that the previous code also technically worked (it is very likely that your original code worked as well). The only difference is that this version makes sure that the drawing sheet is displayed in the drafting application. The previous code switched you to the drafting application, but for some reason the drawing sheet display was turned off. When the drafting sheet display is turned off, it looks very much like you are still in the modeling application.
Switch Application
Hi,
Yes you are right.
Thanks for the help.
Bhavik S.
Hello
Hello
I'm using NX7.5 and I have a compile error
"'ApplicationSwitchRequest' is not a member of 'NXOpen.MenuBar.MenuBarManager'"
Do you know what should I use instead of 'ApplicationSwitchRequest' for NX7.5 ?
Hi
Hi
I have used this in NX10.
I think you are this API is not exposed in NX 7.5.
Bhavik S.