ni.com checkout is currently experiencing issues.

Support teams are actively working on the resolution.

LabVIEW APIs Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How I can programmatically select a menu item?

I have created my own menu bar and a Event structure to execute some functions when item was selected by user.

Now, I want to select programmatically the same item of the menu bar. I don't want to use simulation of keyboard because it doesn't work if PC is logged.

I have found the VI Scripting application method node "User Interaction.Invoke Menu Item". Description in LabVIEW Help is:

Simulates the user selecting a menu item. In general, this method works on global menu items but not document-specific menu items, in which case the method fails silently.

That seems to be the right thing. But when I test the code with my Development System nothing happens. The Event structure is not executed.

I'm new in VI Scripting and need some help.

Best regards,

Ben_B.

0 Kudos
Message 1 of 4
(6,602 Views)

Please post your code so we can take a look. There are a lot of things that can go wrong. Some common ones:

  1. Creating an event before the event structure has registered for the event
  2. Not registering for an event
  3. Not running the event structure

I have done all of these and more, but we can't tell unless you post your code .

0 Kudos
Message 2 of 4
(5,215 Views)

Hi DFGray,

In the attachment you can find the VI.

Thanks in advance for your effort.

Mit freundlichen Grüßen / Best regards,

Ben_B.

0 Kudos
Message 3 of 4
(5,215 Views)

Thanks for the code. Unfortunately, the Invoke Menu Item Method does not work for custom menu items.  From the LabVIEW help "In general, this method works on global menu items but not document-specific menu items, in which case the method fails silently." There is also no similar method to invoke for VI specific menu items. There are workarounds.

  1. Use a user event to trigger the same behavior and create an event to handle it. With your current program structure, this will require duplicating the menu handler event frame in a custom event frame.
  2. Separate your event handling from your task handling by creating a task handling loop in parallel to the event loop (this is my default program structure - it uses the producer/consumer architecture). You can then generate two different events (menu and custom user event) and have them execute the same code.

I realize this does not get you exactly where you want to be, but it should work. Let me know if you have further questions.

0 Kudos
Message 4 of 4
(5,215 Views)