Patrick Zweekhorst avatar image
Patrick Zweekhorst asked Patrick Zweekhorst commented

Different result when running code in debug or not


I have created a small example model which shows my problem in a larger model. The code makes a copy of two conveyors and creates an A-connection between them. There are 3 possible ways to run the code, of which only one seems to work:

1) Just run the scrip by pressing the green run button. The conveyors are created, but the connection is not. If you press the new top right conveyor you will get all kinds of error messages. It is also not possible to delete the conveyor anymore. So this conveyor seems to be broken pretty bad.

2) Run the code in debug mode, but just press run in the debug window. This results in the same thing as point 1.

3) Run the code in debug mode and step through the code line by line. This results in the correct results. The conveyors are created and the connection as well.

What might cause this difference?
Is there a work around for this? Should I call some other functions on the conveyor? Or what is going wrong here?

For reference the code I use:

Object con1 = Model.find("Conveyor1");
Object con2 = Model.find("Conveyor2");
Object newCon1 = createcopy( con1, model() );
Object newCon2 = createcopy( con2, model() );
newCon1.location.y = 5;newCon2.location.y = 5;
contextdragconnection( newCon1, newCon2, "A" );

If something is not clear please let me know.
Thanks for the help,



FlexSim 20.1.2
flexsim 20.1.2connectionsdebugconveyor module
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

anthony.johnson avatar image
anthony.johnson answered Patrick Zweekhorst commented

Haven't opened your model yet, but my initial impression is that you need to call firecreateevent() on the objects that you create. createcopy() unfortunately doesn't call this automatically. They need their OnCreate to fire so they can connect themselves to the conveyor system.

· 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.

Patrick Zweekhorst avatar image Patrick Zweekhorst commented ·

Hi @anthony.johnson,

Thank you for the response. That did solve the problem in my example model.
The only thing is that it did not solve the problem in the original model. I now created a little bit bigger example (see attachment) . The main difference I think is that the conveyors are in a container object and I cope that container. With your advice of the firecreateevent() now also in the code I get some new error messages. In this example case the code does seem to work (it creates the connections), but in the actual model I get the error messages and no connections. Maybe I am doing something wrong with the firecreateevent parameters or something else. Could you take a look at it?

The difference in results is still the same when I step through the code in debug mode. That gives no exceptions and no errors.


0 Likes 0 ·
anthony.johnson avatar image anthony.johnson ♦♦ Patrick Zweekhorst commented ·

@Patrick Zweekhorst In your model, the 5th parameter of firecreateevent (iscopy), should be 1. It looks like you set the 6th parameter to 1 not the 5th. I don't think the 6th parameter matters so much.

Further, the reason it's throwing an exception in the regular execution and not in debugging is because you have a 3D window open. There is 3D code that is firing when you're debugging that is apparently getting the conveyor into a "good" state, so that exceptions don't get thrown when you call firecreateevent(). If you close the 3D view, you'll get the same result when debugging.

0 Likes 0 ·
Patrick Zweekhorst avatar image Patrick Zweekhorst anthony.johnson ♦♦ commented ·

Perfect, that works! I thought we tried that option this morning, but apparently not. Thanks for the help

0 Likes 0 ·