<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Running a python code with Cplex through FlexSim in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582941#M80467</link>
    <description>&lt;P&gt;&lt;I&gt;[ FlexSim 23.0.1 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Hi all,&lt;/P&gt;
 &lt;P&gt;I am trying to run Python through FlexSim. I managed to get the connection between python and flexsim (following this &lt;A rel="nofollow" id="isPasted" href="https://docs.flexsim.com/en/22.2/Reference/DeveloperAdvancedUser/ConnectingToExternalCode/ConnectingToExternalCode.html#python"&gt;https://docs.flexsim.com/en/22.2/Reference/DeveloperAdvancedUser/ConnectingToExternalCode/ConnectingToExternalCode.html#python&lt;/A&gt;) and now I want to run a python code that has a cplex optimization algorithm in it. For the moment I am not feeding any tables or parameters, I want to execute the code and return "1" to get a proof that the code went through. It is not working.&lt;/P&gt;
 &lt;P&gt;I know the code works because I ran it with Jupyter Notebook. &lt;BR /&gt;Can anyone help me figuring out what am I missing?&lt;/P&gt;
 &lt;P&gt;Also, what would be the next step in order to be able to feed a table to the python code and return to flexsim the x[i,j] variable that the cplex calculated?&lt;/P&gt;
 &lt;P&gt;(Flexsim model and python code attached)&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/68074-cplex-test.fsm" target="_blank"&gt;cplex_test.fsm&lt;/A&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/68086-cplex-test-1.py" target="_blank"&gt;Cplex_test_1.py&lt;/A&gt;&lt;/P&gt;
 &lt;P&gt;Thanks&lt;/P&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Mon, 15 May 2023 20:03:10 GMT</pubDate>
    <dc:creator>jacopo_r</dc:creator>
    <dc:date>2023-05-15T20:03:10Z</dc:date>
    <item>
      <title>Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582941#M80467</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 23.0.1 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Hi all,&lt;/P&gt;
 &lt;P&gt;I am trying to run Python through FlexSim. I managed to get the connection between python and flexsim (following this &lt;A rel="nofollow" id="isPasted" href="https://docs.flexsim.com/en/22.2/Reference/DeveloperAdvancedUser/ConnectingToExternalCode/ConnectingToExternalCode.html#python"&gt;https://docs.flexsim.com/en/22.2/Reference/DeveloperAdvancedUser/ConnectingToExternalCode/ConnectingToExternalCode.html#python&lt;/A&gt;) and now I want to run a python code that has a cplex optimization algorithm in it. For the moment I am not feeding any tables or parameters, I want to execute the code and return "1" to get a proof that the code went through. It is not working.&lt;/P&gt;
 &lt;P&gt;I know the code works because I ran it with Jupyter Notebook. &lt;BR /&gt;Can anyone help me figuring out what am I missing?&lt;/P&gt;
 &lt;P&gt;Also, what would be the next step in order to be able to feed a table to the python code and return to flexsim the x[i,j] variable that the cplex calculated?&lt;/P&gt;
 &lt;P&gt;(Flexsim model and python code attached)&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/68074-cplex-test.fsm" target="_blank"&gt;cplex_test.fsm&lt;/A&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/68086-cplex-test-1.py" target="_blank"&gt;Cplex_test_1.py&lt;/A&gt;&lt;/P&gt;
 &lt;P&gt;Thanks&lt;/P&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 15 May 2023 20:03:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582941#M80467</guid>
      <dc:creator>jacopo_r</dc:creator>
      <dc:date>2023-05-15T20:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582942#M80468</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Hey &lt;A rel="user" href="https://answers.flexsim.com/users/42439/jacopo-r.html" nodeid="42439"&gt;@jacopo_r&lt;/A&gt;, I found that the issue was that your file name was using underscores in the code but it was named with dashes in the file explorer.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1684184234258.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1517049iFC3CE2B01BF52EE0/image-size/large?v=v2&amp;amp;px=999" role="button" title="1684184234258.png" alt="1684184234258.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1684184243727.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1517050i6E542C053B50FA0A/image-size/large?v=v2&amp;amp;px=999" role="button" title="1684184243727.png" alt="1684184243727.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If you edit it to match, then it will work.&lt;/P&gt;&lt;P&gt;Alternate ways to connect:&lt;/P&gt;&lt;P&gt;If you scroll up a little on that same doc page, it will point you to the "&lt;A rel="noopener noreferrer" href="https://docs.flexsim.com/en/23.0/Reference/DeveloperAdvancedUser/ConnectingToExternalCode/ConnectingToExternalCode.html#:~:text=At%20the%20bottom%20of%20the%20window" target="_blank"&gt;External&lt;/A&gt;" button which will format the code for Python for you.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1684183933295.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1517051i3C33936A317EDF7F/image-size/large?v=v2&amp;amp;px=999" role="button" title="1684183933295.png" alt="1684183933295.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1684183940132.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1517052i2A0606DF34ECB8DB/image-size/large?v=v2&amp;amp;px=999" role="button" title="1684183940132.png" alt="1684183940132.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If you'd like a more detailed guide, you could check out &lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/questions/123230/how-to-use-flexscript-python-to-create-the-data-in.html" target="_blank"&gt;this post&lt;/A&gt;. Ensure that in your Global Preferences you have the correct Python version selected as well.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1684183960402.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1517053i73A269DB6702AE0F/image-size/large?v=v2&amp;amp;px=999" role="button" title="1684183960402.png" alt="1684183960402.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 15 May 2023 20:52:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582942#M80468</guid>
      <dc:creator>kavika_faleumu</dc:creator>
      <dc:date>2023-05-15T20:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582943#M80469</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 Hi 
 &lt;A rel="user" href="https://answers.flexsim.com/users/35833/kavikaf.html" nodeid="35833"&gt;@Kavika F&lt;/A&gt; , thanks for your answer.
 &lt;P&gt;I did what you suggested but the value I got from the running of the python script is "NULL", while I put a "return 1" at the end of the cplex model just to see if I can actually return something. Does it return "1" to you when you run it?&lt;BR /&gt;Can it be that I miss some settings on FlexSim about Cplex?&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 May 2023 06:10:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582943#M80469</guid>
      <dc:creator>jacopo_r</dc:creator>
      <dc:date>2023-05-16T06:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582944#M80470</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;I got NULL once or twice while testing things out. I think it was because I didn't have the Cplex module installed for my desired version of Python. I had to run&lt;/P&gt;&lt;PRE&gt;py -3.10 -m pip install cplex&lt;/PRE&gt;&lt;P&gt;in my windows PowerShell to make sure that it was installed for the correct version of Python because I have 3.10 and 3.11.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 May 2023 15:14:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582944#M80470</guid>
      <dc:creator>kavika_faleumu</dc:creator>
      <dc:date>2023-05-16T15:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582945#M80471</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 So, as far as you know, there is nothing specific to do in order to make sure that FlexSim can properly access Cplex?
 &lt;P&gt;Thanks again&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 May 2023 15:19:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582945#M80471</guid>
      <dc:creator>jacopo_r</dc:creator>
      <dc:date>2023-05-16T15:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582946#M80472</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;Not that I know of. After installing all the modules for Python 3.10, making sure that my Global Settings &amp;gt; Code tab was set to use Python 3.10, and fixing the names to match, I was getting a 1 as a label for my token. I also tried returning the command in the script console and I got a 1 as well.&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 May 2023 15:41:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582946#M80472</guid>
      <dc:creator>kavika_faleumu</dc:creator>
      <dc:date>2023-05-16T15:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582947#M80473</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 ok, thanks.
 &lt;P&gt;Could you upload the two files you have tested, please? I know they are exactly the same I uploaded, but I want to try also this option and see if something went wrong in mine at some point.&lt;BR /&gt;Thanks&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 17 May 2023 06:51:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582947#M80473</guid>
      <dc:creator>jacopo_r</dc:creator>
      <dc:date>2023-05-17T06:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582948#M80474</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;A rel="user" href="https://answers.flexsim.com/users/35833/kavikaf.html" nodeid="35833"&gt;@Kavika F&lt;/A&gt; I also have another request if possible.
 &lt;P&gt;I basically need to feed the python code with a table from Flexsim, run the cplex, and return (possibly) another table with the assignment of different tasks. I am not quite sure how to do that. I read you post about using python for creating a table and return it to Flexsim and populate it. But what about how python reads a flexsim table?&lt;/P&gt;
 &lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 17 May 2023 07:43:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582948#M80474</guid>
      <dc:creator>jacopo_r</dc:creator>
      <dc:date>2023-05-17T07:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582949#M80475</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Here are the two files I used to get the return value of 1 out of your original question.&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/68198-cplex-test-1.fsm" target="_blank"&gt;cplex-test_1.fsm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/68199-cplex-test-1.py" target="_blank"&gt;cplex-test-1.py&lt;/A&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;You can also upload Global Tables to a Python script. The&lt;A rel="noopener noreferrer" href="https://docs.flexsim.com/en/23.0/Reference/CodingInFlexSim/FlexScriptAPIReference/Data/Table.html#Method-clone" target="_blank"&gt; clone() function&lt;/A&gt; of a Table returns an Array, which can be a &lt;A rel="noopener noreferrer" href="https://docs.flexsim.com/en/23.0/Reference/Tools/UserCommands/UserCommands.html#parameters" target="_blank"&gt;parameter&lt;/A&gt; in a User Command. After hooking up a python function to the User Command, you can pass in a Global Table's clone and get a result. Here's an example of it working (I'll post the files below as well):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1684342844821.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1517056i653A3097EDC88C8B/image-size/large?v=v2&amp;amp;px=999" role="button" title="1684342844821.png" alt="1684342844821.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1684342879411.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1517057iA47D0DADC9B1DFDD/image-size/large?v=v2&amp;amp;px=999" role="button" title="1684342879411.png" alt="1684342879411.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1684342980474.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1517060i5FD5D2FE40732E7A/image-size/large?v=v2&amp;amp;px=999" role="button" title="1684342980474.png" alt="1684342980474.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1684342836340.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1517059iBA1BCED434F91C2A/image-size/large?v=v2&amp;amp;px=999" role="button" title="1684342836340.png" alt="1684342836340.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/68209-cplex-test-2.fsm" target="_blank"&gt;cplex-test_2.fsm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/68214-global-table-1.py" target="_blank"&gt;global-table-1.py&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 17 May 2023 17:03:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582949#M80475</guid>
      <dc:creator>kavika_faleumu</dc:creator>
      <dc:date>2023-05-17T17:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Running a python code with Cplex through FlexSim</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582950#M80476</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 ok, thank you for the answer and the explanation. I'll try to implement this logic :)
&lt;/DIV&gt;</description>
      <pubDate>Thu, 18 May 2023 18:39:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/running-a-python-code-with-cplex-through-flexsim/m-p/13582950#M80476</guid>
      <dc:creator>jacopo_r</dc:creator>
      <dc:date>2023-05-18T18:39:49Z</dc:date>
    </item>
  </channel>
</rss>

