Reputation: 1953
I have an abaqus python script I've been using for a parametric study. It is exhausting to go into the code and edit it every time I want to run different options. I'd like to be able to pass the script arguments so that I can run different options without needing to change the code.
I'd like to do something like this...
abaqus cae script='Script.py --verbose --data=someData.dat'
I've tried the above and I've also tried
abaqus python Script.py --verbose --data=someData.dat
With no success. Is this at all possible?
Upvotes: 9
Views: 8046
Reputation: 1367
Good find Schickmeister. It was not clear to me how to implement, so here is an example
launch abaqus python in cmd.exe
abaqus cae noGUI
enter some python code
>>>import sys
>>>print sys.argv
['C:\\ABAQUS\\6.13-2SE\\code\\bin\\ABQcaeK.exe', '-cae', '-noGUI', '-lmlog', 'ON', '-tmpdir', 'C:\\Windows\\TEMP']
>>>quit()
See how many arguments show up? That's why we need to grab the last one now launch your python script with argument "test.odb"
abaqus cae noGUI=odb_to_video.py -- test.odb
and retrieve the last argument in your script with
odbname = sys.argv[-1]
myOdb = visualization.openOdb(path=odbname)
hope this helps!
Upvotes: 10
Reputation: 1953
@Shickmeister 's answer was exactly what I was looking for, but just to be clear with everything relevant to the question, the latest version of abaqus is far behind the latest version of python. Abaqus currently uses python 2.6, which means argparse is not available. I had to switch to using the deprecated optparse library. Luckily the difference between the two was minor.
Upvotes: 1
Reputation: 1245
From the Abaqus Scripting User's Manual:
Arguments can be passed into the script by entering -- on the command line, followed by the arguments separated by one or more spaces. These arguments will be ignored by the Abaqus/CAE execution procedure, but they will be accessible within the script. For more information, see “Abaqus/CAE execution,” Section 3.2.5 of the Abaqus Analysis User’s Manual, and “Abaqus/Viewer execution,” Section 3.2.6 of the Abaqus Analysis User’s Manual.
Upvotes: 6
Reputation: 1181
It should be possible. Let's see an example if you try to run a command like this:
abaqus python script.py 30 40
30 and 40 are the arguments that the distance.py script will take. Inside the script in python, you should take the first argument as:
import sys
def someFunction(x,y):
#some code
return someThing
if __name__ == "__main__":
x = sys.argv[1]
y = sys.argv[2]
returnedVal = someFunction(x,y)
print (returnedVal)
Upvotes: 2