我可以将命令行参数传递给Abaqus python吗?

时间:2022-01-08 04:15:25

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.

我有一个abaqus python脚本,我一直用于参数研究。每次我想运行不同的选项时,进入代码并编辑它是很累的。我希望能够传递脚本参数,以便我可以运行不同的选项而无需更改代码。

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?

没有成功。这是可能吗?

4 个解决方案

#1


5  

From the Abaqus Scripting User's Manual:

从Abaqus Scripting用户手册:

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.

通过在命令行上输入 - 后跟由一个或多个空格分隔的参数,可以将参数传递到脚本中。 Abaqus / CAE执行过程将忽略这些参数,但可以在脚本中访问它们。有关详细信息,请参阅“Abaqus / CAE执行”,Abaqus分析用户手册的第3.2.5节和“Abaqus / Viewer执行”,Abaqus分析用户手册的第3.2.6节。

#2


5  

Good find Schickmeister. It was not clear to me how to implement, so here is an example

很好找到Schickmeister。我不清楚如何实现,所以这是一个例子

launch abaqus python in cmd.exe

在cmd.exe中启动abaqus python

abaqus cae noGUI

enter some python code

输入一些python代码

>>>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"

看看有多少参数出现了?这就是为什么我们需要抓住最后一个现在使用参数“test.odb”启动你的python脚本

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!

希望这可以帮助!

#3


1  

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:

30和40是distance.py脚本将采用的参数。在python脚本中,你应该把第一个参数作为:

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)

#4


1  

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

@Shickmeister的答案正是我所寻找的,但为了清楚地了解与问题相关的一切,最新版本的abaqus远远落后于最新版本的python。 Abaqus目前使用python 2.6,这意味着argparse不可用。我不得不切换到使用已弃用的optparse库。幸运的是,两者之间的差异很小。

#1


5  

From the Abaqus Scripting User's Manual:

从Abaqus Scripting用户手册:

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.

通过在命令行上输入 - 后跟由一个或多个空格分隔的参数,可以将参数传递到脚本中。 Abaqus / CAE执行过程将忽略这些参数,但可以在脚本中访问它们。有关详细信息,请参阅“Abaqus / CAE执行”,Abaqus分析用户手册的第3.2.5节和“Abaqus / Viewer执行”,Abaqus分析用户手册的第3.2.6节。

#2


5  

Good find Schickmeister. It was not clear to me how to implement, so here is an example

很好找到Schickmeister。我不清楚如何实现,所以这是一个例子

launch abaqus python in cmd.exe

在cmd.exe中启动abaqus python

abaqus cae noGUI

enter some python code

输入一些python代码

>>>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"

看看有多少参数出现了?这就是为什么我们需要抓住最后一个现在使用参数“test.odb”启动你的python脚本

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!

希望这可以帮助!

#3


1  

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:

30和40是distance.py脚本将采用的参数。在python脚本中,你应该把第一个参数作为:

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)

#4


1  

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

@Shickmeister的答案正是我所寻找的,但为了清楚地了解与问题相关的一切,最新版本的abaqus远远落后于最新版本的python。 Abaqus目前使用python 2.6,这意味着argparse不可用。我不得不切换到使用已弃用的optparse库。幸运的是,两者之间的差异很小。