question

Axel Kohonen avatar image
2 Likes"
Axel Kohonen asked Brandon Peterson edited

Create conveyor system in code

Hi,

I am creating a conveyor system consisting of a straight conveyor with a photo eye and a decision point on it. There are multiple of these conveyors next to each other. I manage to create the conveyors and the photo eyes and decision points, but only the first that is created of the photo eyes/decision points works correctly. For the first I create the photo eye into the conveyor using createinstance and Flexsim moves the photo eye to the same rank level as the conveyor and creates the link between them. For the other ones the objects remain inside the conveyor and thus the rest of the code does not work as it should. Also, when stepping through the code with the debugger so that I put breakpoints on the rows where the decision points, photo eyes and before the connections from and to the conveyor are created then the code works as it should, probably due to some timing issue.

Anyone that has a clue on how to fix this problem? See the attached model where the problem is replicated.

Call the createConveyorSystem user command from the script window as I have defined it there to see what happens.

20160606-buildingconveyorsystemwithcode.fsm

FlexSim 16.0.1
conveyorphoto eyedecision pointuser commandautobuild
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
2 Likes"
Matthew Gillespie answered Axel Kohonen commented

After you add a photo eye or a decision point you need to call the finalizeSpatialChanges function on the thing you just added and not on the conveyor. So change these lines:

** Just added a Photo Eye **
function_s(newConveyor,"finalizeSpatialChanges");

** Just added a Decision Point **
function_s(newConveyor,"finalizeSpatialChanges");

To these:

** Just added a Photo Eye **
function_s(photoEye,"finalizeSpatialChanges");

** Just added a Decision Point **
function_s(decisionPoint,"finalizeSpatialChanges");
· 1
5 |100000

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

Axel Kohonen avatar image Axel Kohonen commented ·
20160606-buildingconveyorsystemwithcode-v2.fsm

Thank you Matthew! So finalizeSpatialChanges obviously always needs to be called for the object that you have made changes to. Weird that it worked to call it for the conveyor though when the breakpoints were set in the spots described above.

The corrected model is attached.

Thanks!

Axel

0 Likes 0 ·

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.