question

diego-rt avatar image
0 Likes"
diego-rt asked diego-rt commented

How I can conect a python file with a flexsim model

Good night,

I have a problem with a FlexSim model. I want to connect a process flow with a Python file, where I have a solution for a linear optimization problem. I tried like you have in the next image, but I couldn´t get an answer.

1706571743344.png

In this picture, the first line is the file´s name, and the second one is the function´s name.

Can anyone help me, please?

Regards.


FlexSim 23.0.3
processs flowanswers.flexsim.cominteraction between flexsim and python
1706571743344.png (5.9 KiB)
· 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.

Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·
Is it in the same folder as the model? Have you set the global preferences to the correct python version? Have you toggled the code as external? Have you put it in a user command? Is your custom code calling a user command? Which activity is calling it? Can you attach your files and model?
0 Likes 0 ·
diego-rt avatar image diego-rt Jason Lightfoot ♦ commented ·

I can insert just the Python file. The Flexsim model is too large to send. In addition, I put both files in the same folder, and I selected a Python script in the FlexSim process flow.


If you believe you can help, please text me at my email address, [email protected], so I can send you the FlexSim file. Here is the Python script:

MinCostFlow.py

I am very grateful for every help you can offer me; it is something important to me.


Thank you.

0 Likes 0 ·
mincostflow.py (1.9 KiB)
diego-rt avatar image diego-rt commented ·

Here is more information about how I made my connection and why I do not consider this option a mistake.


1706574870805.png

0 Likes 0 ·
1706574870805.png (34.1 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦ diego-rt commented ·
You can't put flexscript into an external code function like that - you should from your custom code call a user command with parameters to pass to the python function.
0 Likes 0 ·
diego-rt avatar image diego-rt Jason Lightfoot ♦ commented ·
I am not sure about how I should do it because I think I did it in the Python file attached before, if I understood well.
0 Likes 0 ·

1 Answer

·
Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered diego-rt commented

Here's an example of how to call your Python module from a process flow via a user command and have the returned array added to the token as a label.

minCostFlow.zip


mincostflow.zip (28.7 KiB)
· 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.

diego-rt avatar image diego-rt commented ·
Thank you for your help! It was very useful.
1 Like 1 ·

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.