question

Ryosuke S avatar image
0 Likes"
Ryosuke S asked Ryosuke S commented

Destroy all agv in model before starting simulation

Hello, I want to destroy all the agv in the model before I start the simulation. So, at OnModelReset, I wrote a code such as below referring to the reference, but can not seem to get it right. What am I missing?

forobjecttreeunder(model(
{
     Object a;
     if(classobject(a) == library().find("?TaskExecuter"))
     {
         a.destory();
     }
}

Thank you in advance

FlexSim 20.1.3
flexsim 20.1.3flexscript
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

·
Patrick Zweekhorst avatar image
1 Like"
Patrick Zweekhorst answered Ryosuke S commented

Hi @ryosuke.s,

You are defining a variable called a, but this variable already exists in the forobjecttreeunder command. So you are overwriting the variable a. You could do something like Object object = a; But it is not directly needed. Your code should be something like this:

forobjecttreeunder(model( ) )
{   
     if( isclasstype( a, "TaskExecuter" ) == 1 && a.up.up.name != "FlowItemBin" )
     {
         print( a );
         Object object = a;
        object.destroy();
     }
}

Note the extra check in the if statement, where I check if the object is in the flowItemBin. Otherwise the code will not work correctly.

Good luck

· 5
5 |100000

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

Ryosuke S avatar image Ryosuke S commented ·

Hi @patrick.zweekhorst, Thank you for your support. I've tried your code, but when I click reset, only one agv is destroyed at a time. So, if I want to delete 4 agvs, I have to click reset button 4 times. I was thinking that forobjecttreeunder will call all objects in the model and destroy. Is my understanding incorrect?

destroyTE.fsm

0 Likes 0 ·
destroyte.fsm (25.0 KiB)
Patrick Zweekhorst avatar image Patrick Zweekhorst Ryosuke S commented ·

Destroying things in the for loops seems to be stopping the for loop. You can try the following code:

Array teArray = [];
forobjecttreeunder(model( ) )
{   
     if( isclasstype( a, "TaskExecuter" ) == 1 && a.up.up.name != "FlowItemBin" )
     {
        teArray.push( a );
     }
}

for( int i = 1; i <= teArray.length; i++ )
{
    Object te = teArray[ i ];
    te.destroy();
}
1 Like 1 ·
Ryosuke S avatar image Ryosuke S Patrick Zweekhorst commented ·

Hi @patrick.zweekhorst, thank you for your reply. However this code destroys not just the agv but operator and asrs vehicle as well....

0 Likes 0 ·
Show more comments

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.