Adding two Macros in a journal with YES/NO user selection

Hello,

I am currently trying to create a journal running two macros with Yes/No user command selection . I have two separate macros (Macro1 and Macro2) for creating two types of features in UG.

When I run the journal, a Yes or No bar need to come (similar to below code).

1) When I select YES from message bar, it will open and run Macro1
2) When I select NO from message bar, it will open and run Macro2

Journal code I have for creating Message bar is below

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports System.Windows.Forms

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUISession As UI = UI.GetUI
Dim response As Integer

'+----------------------------------+
'¦ ¦
'¦ first, the NX messagebox ¦
'¦ ¦
'¦ ¦
'¦ +--------+ ¦
'¦ ¦ OK ¦ ¦
'¦ +--------+ ¦
'+----------------------------------+

response = theUISession.NXMessageBox.Show("Question", NXMessageBox.DialogType.Question, "DO YOU WANT TO CREATE THIS FEATURE?")
'1 = Yes
'2 = No

'My requirement: If response=yes then open "C:\Users\myname\Documents\Macro1.macro" need to run
'If response=No then open "C:\Users\myname\Documents\Macro2.macro" need to run

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

Thanks

There is no good way to call a macro from a journal. I would recommend creating journal code to do whatever it is that the macro does (if possible) and incorporate it into your overall journal. This will make maintaining the code much easier.

Here is a thread on eng-tips where someone claims there is an "undocumented" function to call a macro:
http://www.eng-tips.com/viewthread.cfm?qid=367518

I've not used it, so I can't comment on how effective it is; but the "undocumented" aspect makes me a bit skeptical that it will work reliably.

Hi,

I am from NX design background, not much knowledge about programming code.

The macros (Macro1 and Macro2) are invoking a .dll files which perform some operations according to my company standards (Ex: create std layers, std ref.sets, clean part geometry etc.) .
I dont have right to edit those .dll files. So, what I did is create two macros. Macro1 invoke a particular .dll file and Macro2 invoke another .dll file.

Now I required to invoke either of these two macros using Yes/No user selection in a journal.
Scenario1: If the user click Yes button, it will invoke "Playback Macro" then select "Macro1" location and "Run".
Scenario2: If the user click No button, it will invoke "Playback Macro" then select "Macro2" location and "Run"

When I tried in a journal, I was to able to invoke either scenario 1 (using Yes button click) or scenario2 (using No button click). But I dont have idea how to combaine these two scenarios in a single Journal.

I have the journal code for creating Yes Or No message box (attached previously and reattaching).

My intention is
when I click Yes (Response=1), it will invoke Macro1 (ie,Menu-Tools-Macro-Playback-Select Macro1.macro) (Macro1.macro Location is C:\Users\myname\Documents\Macro1.macro)
when I click Nes (Response=2), it will invoke Macro2 (ie,Menu-Tools-Macro-Playback-Select Macro2.macro) (Macro2.macro Location is C:\Users\myname\Documents\Macro2.macro)

I believe this is possible, only I am lacking is some logic VB command knowledge since I am not from programming background.

Approx code will be some thing like below where I have mentioned "My requirement codes"
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports System.Windows.Forms

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUISession As UI = UI.GetUI
Dim response As Integer

'+----------------------------------+
'¦ ¦
'¦ first, the NX messagebox ¦
'¦ ¦
'¦ ¦
'¦ +--------+ ¦
'¦ ¦ OK ¦ ¦
'¦ +--------+ ¦
'+----------------------------------+

response = theUISession.NXMessageBox.Show("Question", NXMessageBox.DialogType.Question, "DO YOU WANT TO CREATE THIS FEATURE?")
'1 = Yes
'2 = No

'My requirement: If response=yes then perform "Menu-Tools-Macro-Playback-Select Macro1.macro"
'If response=No then perform "Menu-Tools-Macro-Playback-Select Macro2.macro"

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

For the code that you posted above, you can check the "response" variable to see whether the user selected "yes" or "no".

if response = 1 then
'user selected "yes"
'add code for "yes" response
else
'user selected "no"
'add code for "no" response
end if

Do you have an NXOpen author license? In other words, can you sign and compile your journals to dll or exe files? If so, you can reference the existing dll files and call them as necessary - no macros needed. You would be able to call the dll files directly from your code, eliminating the need for the macros.

Whether you have an author license or not, there is no good way for a journal to execute a macro. You can try the "undocumented" function that I pointed you to earlier, but I've never used it so I can't add anything beyond what is in the other thread.

What would be some example code to call the existing .dll to call from VB?

I have this same situation where I don't have any control over these dll, but I need to call them as a process. Thanks.

Regards,
MFJ

https://community.sw.siemens.com/s/question/0D54O000061xKz0SAE/communica...

The link above has a PDF document about communicating with Excel from the NXOpen API. In the document, they add a reference to the Excel DLL and then in the code, they can make use of the Excel object model (objects, properties, methods, etc).

Thanks for the idea. In my case, the dll actually runs a form. I tried adding the dll as a reference to my project. But all I want is actually to bring the form (which users are familiar with) in the middle of my routine for user to fill the form.

Regards,
MFJ

Also forgot to mention that he form is also a created using UI styler. The dll is running a .dlx form file.

Regards,
MFJ