Running existing VC commands from .NET

Hello,

I am trying to run existing commands like Measure or Snap from my custom .NET function. After executing fuction according to their ID nothing happend. So i tried another existing function and find out some strange behaviour.

Trying to run “FillSelected” to zoom in all selected component. Using code below and all works.

             ICommandRegistry cmd = IoC.Get<ICommandRegistry>();
             IActionItem extractCmd = cmd.FindItem("FillSelected");
             extractCmd.Execute();

But when trying to run very similar fucntion “FillWorld” with same code, nothing happend and seems like function dont work.

My final goal is make working the Snap function to use it in my custom function. Also trying to run Snap or Measure with code below and still dont work.

            ICommandRegistry cmd = IoC.Get<ICommandRegistry>();
            ICommandPanelAction commandPanelAction = IoC.Get<ICommandPanelAction>();

            IActionItem extractCmd = cmd.FindItem("SnapPrimitiveCommand");  (or "Measure")

            cmd.StartCommandPanelAction(extractCmd, commandPanelAction);

            commandPanelAction.StartAction();
            extractCmd.Execute();

Anyone meet this problem, or know the right way to start these types of function?

Thank you

Maybe try executing them through the command registry. Some commands may also require parameters.
Also note that I think generally only one command can be running at the time, so if your code is a command with a command panel, running another command may cancel yours.

Commands (or rather ActionItems) also have restrictions about the context when they can be run, such as correct type of selection in ISelectionManager, or correct application context (e.g. home, modeling). There is CanExecute property (or was it a method) in actionitems.

Thank you for your reply. I already tested the proposed solution, but still dont work. But this help me to think about whole problem.

The problem was in running the .Net commands (ActionItems) using python script and not directly from .NET button in UI added in .cofig of Visual Components. After changing the way i runs my funciton to .NET, all ActionItems start running correctly.