I want to start a new simulation in Process Simulate via the API. Unfortunately the simulation time is not updated although the controls for the simulation are disabled. The code I use is the following:
TxTypeFilter opFilter = new TxTypeFilter(typeof(ITxOperation));
TxOperationRoot opRoot = TxApplication.ActiveDocument.OperationRoot;
TxObjectList allOps = opRoot.GetAllDescendants(opFilter);
ITxOperation lineSimOp = null;
foreach(ITxOperation op in allOps)
lineSimOp = op;
if (lineSimOp != null)
TxSimulationPlayer simPlayer = TxApplication.ActiveDocument.SimulationPlayer;
What am i missing here? What is the difference when a new TxSimulationPlayer object is created compared to using the one referenced by the active document?
thanks in advance
Solved! Go to Solution.
try to set the current operation of the study instead of setting the operation for the simulation player:
TxApplication.ActiveDocument.CurrentOperation = lineSimOp;
I've tried that before. Unfortunately, it doesn't help. Even doing both - setting the CurrentOperation of the study and calling setOperation doesn't work.
There is a member of TxSimulationPlayer which determines whether the UI is updated....TxSimulationPlayer.RefreshMode. Interestingly, it is a read-only property and I haven't found a way to set it to true
I've tried to use TxApplication.ActiveDocument.SimulationPlayer and also got some bad results. Try to create a new instance of TxSimulationPlayer. This new instance has no events registered to it, so it looks more "stable" for customization purposes:
TxSimulationPlayer player = new TxSimulationPlayer();
By the way, refresh mode is a property based on the methods Play() and PlayWithoutRefresh(). Play() will refresh graphics viewer while PlayWithoutRefresh() will not.
1. you can try using TxApplication.CommandsManager.ExecuteCommand with the specific command's id or name and paramters that you need. such information can be founded in NewAssembler.xml.
2. there is also specific API for Path Edior TxPathEditorViewer
the idea of using internal commands was one we've also thought of but haven't tried yet, because
- We've just considered it to be a different "frontend" to the same internal functionality and
- We were not sure which type of parameter to use.
Your suggestion motivated me to do try the method ExecuteCommand for "Operations.PlayForward" using no parameter at all and it worked. However, there are "Operations"-related commands that definitely need parameters if they are not bringing up a UI allowing the user to specify them interactively. Unfortunately there are only some command parameter types documented in the Tx SDK help
Thanks and kind regards
1. Which exact commands you are trying to use but you can't due to paramters?
2. Note: just keep in mind, that the command's name\id\parameters for ExecuteCommand may be change in the future (unlike any official API)
My comment on the command parameters was just an observation I made when looking at the newAssembler.xml file. An example for a command that seems to need a parameter is Operations.EditOperations. However, I don't want to call it.
We are considering the internal commands the last resort to use when we don't succeed to use the API directly....For instance: Just invoking the Play() method on the SimulationPlayer instance of the ActiveDocument is not enough to get a "normally" running simulation (including correct UI Update). That's why we reverted to the internal commands.
Thanks for getting back.
Just keep in mind that even commands inside PS (like Automatic Path Planner, Wept Volume, Move to Location etc.) play the simulation by SimulationPlayer with\without refresh. The clocks in the viewers in this case are not working (since you run an external simulation) but the robots are moving as expected.