question

Lucas Klein avatar image
0 Likes"
Lucas Klein asked Phil BoBo commented

Module SDK - onRunStart

Hello

I am working with the module SDK and noticed that there is the function "onReset".

1658337909032.png

I would like to know if is there any function that executes within the start of the model, such as "onRunStart". I've tried to use the "onSimulationStart" but had no success on making this work out, I've declared it inside my object, but when I run the model the function just does not trigger.

Declaration on my object.h

1658338107635.png

Declaration on my object.cpp

1658338161592.png


Please tell me if I'm doing something incorrect, or if there is any other function that I can use on the start of the simulation.


Thanks in advance.

FlexSim 21.2.4
module sdkdevelopmentmodules
1658337909032.png (5.2 KiB)
1658338107635.png (4.4 KiB)
1658338161592.png (11.2 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Jordan Johnson avatar image
3 Likes"
Jordan Johnson answered Phil BoBo commented

In order for FlexSim to call the onStartSimulation() method on your object, you need to call SimulationStartEvent::addObject() in the onReset method:

class MyClass : public FlexSimEventHandler /*or any subclass of FlexSimHandler*/
{
public:
  virtual double onReset() override { 
    print("onReset"); 
    SimulationStartEvent::addObject(this);
    return 0; 
  }
  virtual double onStartSimulation() override { print("onStartSimulation"); return 0; }
};

The SimulationStart mechanism adds a single event at time zero. When that event executes, it calls the onStartSimulation() method for all the objects in its list. You can see this in MAIN:/project/exec/globals/includebody, around line 550.

There is also a PostReset mechanism, but FlexSimEventHandler doesn't implement that method. So you'd need to add the OnPostReset eventfunction to your class in the library, which calls your class' onPostReset method. Finally, the onReset can call SimulationStartEvent::addPostResetObject(). PostReset is basically a second pass during the model's reset, and the simulation start event happens at time zero.

· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Lucas Klein avatar image Lucas Klein commented ·
Thanks a lot @Jordan Johnson !
0 Likes 0 ·
Lucas Klein avatar image Lucas Klein commented ·

Talking about model triggers, is there any way to trigger the "onModelOpen" by my module?

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Lucas Klein commented ·

Add a node to MAIN:/project/events/OnOpenModel

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.