question

Sri_vikas K avatar image
0 Likes"
Sri_vikas K asked Logan Gold commented

Calling the python script located in my PC using custom code to execute it.

Hi cammunity,

I am attempting to call a Python script stored in my local storage from FlexSim using the script below. However, I am encountering errors related to calling external commands and handling messages. I would appreciate any help or suggestions on how to resolve these issues and successfully execute the Python script from FlexSim.


// Define the path to Python and the Python script

string pythonExePath = "Storage Path"; // Path to Python executable

string scriptPath = "Storage Path"; // Path to your Python script


// Prepare the command to run

string command = pythonExePath + " \"" + scriptPath + "\""; // Make sure to handle spaces in paths


// Run the command using callExternal()

int result = callExternal(command);


// Check the result to see if the script was called successfully

if (result == 0)

{

message("SMS sent successfully!");

}

else

{

message("Failed to send SMS. Error code: " + result);

}

Execute python Script.fsm

Thanks in advance for your assistance!

FlexSim 23.1.4
python connection with flexsim
· 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.

1 Answer

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Felix Möhlmann commented

"callExternal" and "message" are not valid commands.

To run python code, it's easiest to set up a user command that links to the python function you want to execute. The parameters of the user command will be passed to python and the return value of the python function is returned as the result of the user command.

https://docs.flexsim.com/en/23.1/Reference/DeveloperAdvancedUser/ConnectingToExternalCode/ConnectingToExternalCode.html#python

See also the post below.

https://answers.flexsim.com/questions/158244/how-i-can-conect-a-python-file-with-a-flexsim-mode.html

· 4
5 |100000

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