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.

Matthew Gillespie avatar image Matthew Gillespie ♦♦ commented ·
@Rohan V3 What do you do after you start a new model? I added the conveyor to the user library and then dragged out the conveyor in a new model, and reset the labels and it seems to work fine. I'm not seeing any crashing issues. Can you tell me the exact steps you're doing?
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Matthew Gillespie ♦♦ commented ·
And it works in you test model too in 21.0.8. Setting the 'Built' label to zero each time to force the rebuild.
0 Likes 0 ·
Rohan V3 avatar image Rohan V3 Jason Lightfoot ♦♦ commented ·

Interesting.. @Matthew Gillespie Did you try changing the conveyor length? It crashes when I change the length, increase or decrease it. Change the conveyor length label on the conveyor. If it still works for you, can you attach your model and I can see if that file works.

0 Likes 0 ·
Show more comments

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.

Object current = ownerobject(c);
Array dps = current.DP;

// Delete Existing DPs
while (dps.length)
    dps.pop().destroy();

// Set Conveyor Length
current.size.x = current.Conv_Length;
function_s(current,"finalizeSpatialChanges");

//Create Start DP
treenode startdp = createinstance(maintree().find("project/userlibrary/MDR/Start DP"), current);
setloc(startdp, current.zone_Length - 7.875,0,0);
dps.push(startdp);
function_s(startdp,"finalizeSpatialChanges");

//Create Intermediate DP
int dpnum = (current.Conv_Length/current.zone_Length) - 2;

for (int i = 1;i<=dpnum;i++){
    treenode mdrdp = createinstance(maintree().find("project/userlibrary/MDR/MDR DP"), current);
    double dist_along_conv;
    dist_along_conv = (i+1)*current.zone_Length - 7.875;
    setloc(mdrdp, dist_along_conv,0,0);
    dps.push(mdrdp);        
    function_s(mdrdp,"finalizeSpatialChanges");

    //function_s(current,"finalizeSpatialChanges");
}

// Create END DP
treenode Enddp = createinstance(maintree().find("project/userlibrary/MDR/End DP"), current);
setloc(Enddp, current.Conv_Length - 7.875,0,0);
dps.push(Enddp);
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.

Rohan V3 avatar image Rohan V3 commented ·
Great! this works. Couple of questions:

Were you able to replicate the crashing? Was the append array the issue?



0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Rohan V3 commented ·
@Rohan V3 Yes, I was able to replicate FlexSim hanging. I'm not totally sure what the issue was, but started cleaning up your code to narrow down the issue and after making the above changes to your code I stopped seeing the issue.
0 Likes 0 ·