Cancel
Showing results for 
Search instead for 
Did you mean: 

Start a simulation via API in TX

Siemens Creator Siemens Creator
Siemens Creator

Dear all,

 

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)
{
    if (op.Name.Equals("LineOperation"))
    {
        lineSimOp = op;
        break;
    }
}

if (lineSimOp != null)
{
    TxSimulationPlayer simPlayer = TxApplication.ActiveDocument.SimulationPlayer;
    simPlayer.SetOperation(lineSimOp);
    simPlayer.Play();
}

 

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

Lars

8 REPLIES

Re: Start a simulation via API in TX

Experimenter
Experimenter

Hello Lars,

 

try to set the current operation of the study instead of setting the operation for the simulation player:

TxApplication.ActiveDocument.CurrentOperation = lineSimOp;

 

Regards

Bjoern

Re: Start a simulation via API in TX

Siemens Creator Siemens Creator
Siemens Creator

Hi Björn,

 

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 Smiley Sad

 

best regards

Lars

Re: Start a simulation via API in TX

Phenom
Phenom

@califax2k

 

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.

 

Reagrds,

 

Re: Start a simulation via API in TX

Siemens Genius Siemens Genius
Siemens Genius

Hi,

 

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

 

Regards,

Moshe

Re: Start a simulation via API in TX

Siemens Creator Siemens Creator
Siemens Creator

Hi Hazan,

 

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 Smiley Sad

 

Thanks and kind regards

Lars

Re: Start a simulation via API in TX

Siemens Genius Siemens Genius
Siemens Genius

Hi Lars,

 

 

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)

 

Regards,

MosheH

 

Re: Start a simulation via API in TX

Siemens Creator Siemens Creator
Siemens Creator

Dear Moshe,

 

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.

 

regards

Lars 

Re: Start a simulation via API in TX

Siemens Genius Siemens Genius
Siemens Genius

Hi Lars,

 

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.

 

Regards,

Moshe