Hello,
how can I give an argument to a script that I want to run in salome (python interface inside salome GUI)?
when I run a script from the gui in the console is runned the following command:
If you want to pass arguments to a script you can do this:
salome myscript.py args:arg0,arg1
Then in the script sys.argv[0] is the name of the script and sys.argv[1:] the rest of the arguments.
See the example attached to create a block with 3 parameters:
Hello fred,
giving arguments to a script from the terminal wasn’t the issue (I excuse myself if I wasn’t clear enough I my original post).
what I am looking to do is be able to pass arguments when in the GUI we do file/load script…
this will run in the salome python console the following function: exec(compile(open('/pathToScript/script.py', 'rb').read(), '/pathToScript/script.py', 'exec'))
I wanted to be able to modify this line to be able to give arguments to the script.py
I know that I can give them when running in the terminal (thanks to one of your previous posts actually!) but it is not what I am looking for right now. as I have a script that I select an object in the interface, and want to run it so it export some parts of it and want to give as input the path to where to export.
From the Python Console of SALOME you can pass the arguments like this:
exec(open(“C:\SALOME-9.12.0\block.py”, “rb”).read(), args=(“20”,“30”,“40”))
But if you need to retrieve the selection then it is different.
You probably should try to create a plugin instead and you will be able to create a small GUI to get the needed parameters.