question

Rohan V3 avatar image
0 Likes"
Rohan V3 asked Matthew Gillespie commented

Build Decision Point with Code

MDR.fsl

Test_Model_1.fsm

MDR is the library which has 3 DPs that I am using to build the model. The conveyor has an on reset code which deletes the DPs and creates new ones. If you start a new model and run the code the first time it works. After that, the model keeps crashing everytime I hit reset.

FlexSim 21.0.4
conveyorcodeconveyorsystemdecision pointflexsim 21.0.4
mdr.fsl (2.6 KiB)
test-model-1.fsm (41.1 KiB)
· 6
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

Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered Matthew Gillespie commented

I cleaned up your script to use better array access and methods and I'm no longer seeing the crashing issue. Array.push() is better than making an array of a single thing and appending that array.

  1. Object current = ownerobject(c);
  2. Array dps = current.DP;
  3.  
  4. // Delete Existing DPs
  5. while (dps.length)
  6.     dps.pop().destroy();
  7.  
  8. // Set Conveyor Length
  9. current.size.x = current.Conv_Length;
  10. function_s(current,"finalizeSpatialChanges");
  11.  
  12. //Create Start DP
  13. treenode startdp = createinstance(maintree().find("project/userlibrary/MDR/Start DP"), current);
  14. setloc(startdp, current.zone_Length - 7.875,0,0);
  15. dps.push(startdp);
  16. function_s(startdp,"finalizeSpatialChanges");
  17.  
  18. //Create Intermediate DP
  19. int dpnum = (current.Conv_Length/current.zone_Length) - 2;
  20.  
  21. for (int i = 1;i<=dpnum;i++){
  22.     treenode mdrdp = createinstance(maintree().find("project/userlibrary/MDR/MDR DP"), current);
  23.     double dist_along_conv;
  24.     dist_along_conv = (i+1)*current.zone_Length - 7.875;
  25.     setloc(mdrdp, dist_along_conv,0,0);
  26.     dps.push(mdrdp);        
  27.     function_s(mdrdp,"finalizeSpatialChanges");
  28.  
  29.     //function_s(current,"finalizeSpatialChanges");
  30. }
  31.  
  32. // Create END DP
  33. treenode Enddp = createinstance(maintree().find("project/userlibrary/MDR/End DP"), current);
  34. setloc(Enddp, current.Conv_Length - 7.875,0,0);
  35. dps.push(Enddp);
  36. function_s(Enddp,"finalizeSpatialChanges");
· 2
5 |100000

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