Can I pass command-line arguments to Abaqus python?

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=' --verbose --data=someData.dat'

I've tried the above and I've also tried

abaqus python --verbose --data=someData.dat

With no success. Is this at all possible?

Asked by: Daryl289 | Posted: 30-11-2021

Answer 1

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']

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 -- test.odb

and retrieve the last argument in your script with

odbname = sys.argv[-1]
myOdb = visualization.openOdb(path=odbname)

hope this helps!

Answered by: Patrick341 | Posted: 01-01-2022

Answer 2

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.

Answered by: John463 | Posted: 01-01-2022

Answer 3

It should be possible. Let's see an example if you try to run a command like this:

abaqus python 30 40

30 and 40 are the arguments that the 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)

Answered by: Rafael300 | Posted: 01-01-2022

Answer 4

@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.

Answered by: Blake324 | Posted: 01-01-2022

Similar questions

python - How to prompt for user input and read command-line arguments

Closed. This question needs to be more focused. It ...

python - command-line options and arguments using getopt

I'm trying to write a piece of code in python to get command-line options and arguments using getopt module. Here is my code: import getopt import sys def usage (): print('Usage') def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'xy:') except getopt.GetoptError as err: print(err) usage() sys.exit() for o,a in opts: if o in ("-x", "--xxx"):...

ruby on rails - UTF-8 minus sign rejected in python command-line arguments

I am running python 2.6 on Ubuntu Lucent and having trouble getting the minus sign in negative command-line arguments to be interpreted properly, especially when the call to the script is initiated through the OS via Rails (using backquotes). In particular, the minus sign seems to be coming in as UTF-8. When command-line arguments are interpreted manually, as in: lng = float(sys.argv[4])

python - Passing Command-line Arguments in C++

I've been trying to learn how to extend Python 3 with C++, and I was recommended using Boost. I believe I've followed the procedure of setting up Boost::Python correctly so far, and I have the following code from here (saved as example.cpp) which builds successfully: #incl...

python - How can I get the command-line arguments in an embedded Pig script?

I'm writing an embedded pig script in python, and I'd like to pass arguments like this: $ pig arg1 arg2 I'd expect sys.argv to be ['', 'arg1', 'arg2'], but it's empty. Any idea how I can pass command-line arguments to an embedded pig script?

python - Parsing command-line arguments similar to archlinux pacman

I'm creating a python script with usage in the same style as pacman in Arch Linux, summarized by: prog <operation> [options] [targets] operations are of the form -X (hyphen, uppercase letter), and one is required when calling the script. options are of the form -x ...

How to access command-line arguments from a Python script?

I am writing code in Python that I should run with the command line and when I call the script i should give some arguments that I would use in the code. What can I use to achieve that? To run the script it would be something like this: python s1 s2 s4 where s1, s2 and s4 would be the arguments that I would use in my code.

Passing Strings as Python command-line arguments

I’m able to pass ints and chars as Python command-line args, but can’t pass Strings successfully to the following: if __name__ == '__main__' : try : print(len(sys.argv)) arg1 = ast.literal_eval(sys.argv[1]) arg2 = ast.literal_eval(sys.argv[2]) print(arg1) print(arg2) except Exception : print('error') The following works:

Parsing command-line arguments in Python: array of variable length?

is it possible to create an array in Python with an variable length? I'm getting different kind of length from sys.argv when I start the program and I need as much array field as long as the string from sys.argv is. EDIT for better understanding: I wrote a python script which can controle the GPIO Ports of a Raspberry Pi Until now, the script is just able to control one port at the same time...

python - Provide command-line arguments for function in file

This question already has answers here:

linux - How to make a python, command-line program autocomplete arbitrary things NOT interpreter

I am aware of how to setup autocompletion of python objects in the python interpreter (on unix). Google shows many hits for explanations on how to do this. Unfortunately, there are so many references to that it is difficult to find what I need to do, which is slightly different. I need to know how to enable, tab/auto completion of arbitrary items in a command-line program written in ...

java - OCSP command-line test tool?

Closed. This question does not meet Stack Overflow guid...

python - How to prompt for user input and read command-line arguments

Closed. This question needs to be more focused. It ...

eclipse - Integrating command-line generated python .coverage files with PyDev

My build environment is configured to compile, run and create coverage file at the command line (using Ned Batchelder tool). I'm using Eclipse with PyDev as my editor, but for practical reasons, it's not possible/convenient for me to convert my whole build environment to Eclipse (and thus generate the coverage data directly from the IDE, as it's designed to do) PyDev seems to be using the same ...

c++ - How do I compile a Visual Studio project from the command-line?

I'm scripting the checkout, build, distribution, test, and commit cycle for a large C++ solution that is using Monotone, CMake, Visual Studio Express 2008, and custom tests. All of the other parts seem pretty straight-forward, but I don't see how to compile the Visu...

How to make a simple command-line chat in Python?

I study network programming and would like to write a simple command-line chat in Python. I'm wondering how make receving constant along with inputing available for sending at any time. As you see, this client can do only one job at a time: from socket import * HOST = 'localhost' PORT = 21567 BUFSIZE = 1024 ADDR = (HOST, PORT) tcpCliSock = socket(AF_INET, SOCK_STREAM) tcpCliSock.connect(A...

interpreter - Persistent Python Command-Line History

I'd like to be able to "up-arrow" to commands that I input in a previous Python interpreter. I have found the readline module which offers functions like: read_history_file, write_history_file, and set_startup_hook. I'm not quite savvy enough to put this into practice though, so could someone please help? My thoughts on the solution are: (1) Modify .login PYTHO...

data structures - Processing command-line arguments in prefix notation in Python

I'm trying to parse a command-line in Python which looks like the following: $ ./command -o option1 arg1 -o option2 arg2 arg3 In other words, the command takes an unlimited number of arguments, and each argument may optionally be preceded with an -o option, which relates specifically to that argument. I think this is called a "prefix notation". In the Bourne shell I wo...

Display constantly updating information in-place in command-line window using python?

I am essentially building a timer. I have a python script that monitors for an event and then prints out the seconds that have elapsed since that event. Instead of an ugly stream of numbers printed to the command line, I would like to display only the current elapsed time "in-place"-- so that only one number is visible at any given time. Is there a simple way to do this? If possible I'd like to u...

python - How to write script output to file and command-line?

I have a long-running Python script that I run from the command-line. The script writes progress messages and results to the standard output. I want to capture everything the script write to the standard output in a file, but also see it on the command line. Alternatively, I want the output to go to the file immediately, so I can use tail to view the progress. I have tried this: python MyLongRu...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python