NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Command.Enabled property for UI API doesn't work

As an example of what I am trying to do, I would like to disable the "Open Sequence File" command button and menu in my TestStand OI if a sequence file is already open.

 

So in my SequenceFileChanged event callback VI, I get the command from the SequenceFileViewManager (using the GetCommand() function with CommandKind input of "CommandKind_OpenSequenceFile") and then set the Command.Enabled to either True or False.  But setting the property doesn't seem to have any effect on the UI control or menu item to which the command is connected.  (I have also tried the Command.Visible property without any effect.)

 

I can read the property immediately before and after I set it, and the value I read confirms that the value changes when it supposed to; but the value seems to revert once the callback VI finishes, because the next time the VI is called, the value I read is not always the value that I read in the previous call.  It's like the Command object loses scope when the VI exits and never gets written to the Manger control.

 

During the initialization of my program, when I connect my UI button to the command using SequenceFileViewMgr.ConnectCommand(), I have tried using a value of CommandConnection_IgnoreEnable (0x4) for the CommandConnectionOptions input to the function, but that doesn't seem to help either.

 

Am I going down the right path to programmatically enable/disable command buttons, or am I completely off base here?

 

 

Jeff

 

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

Hi jsiegel, 

 

Have you seen this community example? It looks like it may be similar to the type of functionality you are looking for. Here is the link to the download: http://www.ni.com/example/31024/en/

Here are screen shots and some implementation advice: https://decibel.ni.com/content/docs/DOC-31313

It might be a little old, but it could be useful.

Rachel M.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 6
(4,571 Views)

The command object GetCommand returns is a fresh instance. If you modify it, it doesn't affect the instance the button connects to or any new instances you create of the command.

 

I think you were on the right track by using CommandConnection_IgnoreEnable. The next step would be to explicitly set the Button.Enabled property on the button. However, the menu is another story. I'm not familiar with that code, but somewhere the menu item is being created and you'll need to do something similar at that point. It might be created as part of a set of items, in which case you'll have to replaced that creation by explicity creating the items in the set so you have control over the item you want. Alternatively, there might be way to modify it after it has been inserted, but that would require a look into the environment specific code that hooks up menu items to commands.

 

Of course, you can always create the relevant menu items in the usual environment specific fashion, using command objects to help you decide when to enable (except when you explicitly want to do something else) and to do the actual work when the item is invoked.

0 Kudos
Message 3 of 6
(4,563 Views)

Thanks, Rachel and James, for your responses.  My goal was to have a single function (or property) disable all buttons (or menu items) associated with a command and have the Manager control take care of everythign.  But you both suggest setting the Enabled property for each specific control.  What then is writing the value of Command.Enabled supposed to do?  I can see that you can set the Disabled property of the Command output from SequenceFileViewMgr.ConnectCommand() (with the Options input set CommandConnection_IgnoreEnable) to disable the button associated with the command.  But since the Command is associated only with the specified button, it doesn't seem any different from setting the button's Enabled property directly.  (And setting the button's Enabled property directly seems to make the CommandConnection_IgnoreEnable option for ConnectCommand() irrelevant, unless the links Rachel refers to fail to specify that is a requirement.)

 

The TestStand VI to build menus creates a new Command object for the desired commands and checks their Enabled property to determine whether or not to disable the associated menu item--so TestStand clearly sets this property for all instances of a Command object for a given command.  But I have no way of accessing the instance created by the VI in order to explicitly change its value (without ditching the VI and creating my own).  By the way, that VI assigns menu tags that are named arbitrarily based on the order they were created, so as far as I can tell it's not a simple task to figure out the menu tag associated with a specific command in order to explicitly disable it later.

 

So I guess the bottom line is that I have to manage the states of my buttons and menu items individually, and not try to set a property of a Command, if I want their states to be different from what TestStand normally would want them to be.  Would you agree?

 

Thanks for your help.

 

 

Jeff

 

 

0 Kudos
Message 4 of 6
(4,556 Views)

"What then is writing the value of Command.Enabled supposed to do?"

Not a lot. If you have a command object and then pass it to something else, the I guess you could use it to communicate a different enabled state, but it only applies to that instance of the command object.The main purpose of the enabled property is to tell you (or code that attaches a UI element to a command) whether TestStand thinks an action should be enabled given the current state.


"So I guess the bottom line is that I have to manage the states of my buttons and menu items individually, and not try to set a property of a Command, if I want their states to be different from what TestStand normally would want them to be.  Would you agree?"

Yes, but the commands can still help you implement the functionality.

0 Kudos
Message 5 of 6
(4,547 Views)

Okay, thanks James.

0 Kudos
Message 6 of 6
(4,536 Views)