I would have liked to execute some code when an object is deleted in the 3D view.
- while the simulation is stopped
- not in onModelReset
For example: delete a row in a global table when a Processor is deleted.
Any idea how to do it?
Thanks!
I would have liked to execute some code when an object is deleted in the 3D view.
For example: delete a row in a global table when a Processor is deleted.
Any idea how to do it?
Thanks!
1. You can add an OnDestroy attribute to the object's eventfunctions in order to have a callback when the object is destroyed.
You can return 1 in OnDestroy to prevent the object from being destroyed. For example, if you wanted to add a message box for the user to confirm that they want to delete the object.
Also, when you override an event function on an object, you should almost always call inheritcode() so that it executes the class object's version of that function. Otherwise, the default behavior of that function will not happen.
2. You can also use nodejoin() to couple two nodes together so that when one is destroyed, the other is also destroyed.
Attached is a sample model that shows both of these methods.
The queue has an OnDestroy attribute that fires custom code when it is destroyed.
The processors each have a node within their stored attribute that is linked to a global table row so that when you destroy the processor, it deletes the table row.
The script windows show how I linked the processors to the global table and how you can programmatically add the OnDestroy node to the queue.
I don't understand what you mean by the conditions:
Thank you!
This is exactly what I was looking for.
By "not in onModelReset", I meant that it was not necessary to reset the model to execute this code.
By "while the simulation is stopped", I meant that it was not necessary to have the simulation running to execute this code
@David Besson Because you have given very little information I don't know why you want to do this? It sounds very strange to remove objects in the middle of a run? Can't you make a gui where you can select an object to delete? That way you have complete control.
To answer the original question I think there are several approached possible:
1. If the object is deleted by code you can do it in that code obviously so I guess you want this when somebody manually deletes an object.
2. If you create your own module object you have a destructor to this.
3. you can use the onrun start trigger. So if you stopped the model, removed an object and start the continued run, the run start trigger is fired.
4. Last option you could have a piece of code that runs continuously (like a plc loop) by writing an ondraw trigger, that checks if an object does not exist anymore. If it not exists you can do some stuff. Advantage of this method is also if you close your windows for a fast run it is not executed. But it is not a very nice solution and if possible avoid it. An important rule is to never write logic on the ondraw that is needed for running the model.
8 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved