简体   繁体   English

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

[英]Can I pass command-line arguments to Abaqus python?

I have an abaqus python script I've been using for a parametric study. 我有一个abaqus python脚本,我一直用于参数研究。 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? 这是可能吗?

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. 这些参数将被Abaqus / CAE执行过程忽略,但它们可以在脚本中访问。 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分析用户手册的第3.2.5节和“Abaqus / Viewer执行”,Abaqus分析用户手册的第3.2.6节。

Good find Schickmeister. 很好找到Schickmeister。 It was not clear to me how to implement, so here is an example 我不清楚如何实现,所以这是一个例子

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! 希望这可以帮助!

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. 30和40是distance.py脚本将采用的参数。 Inside the script in python, you should take the first argument as: 在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)

@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. @Shickmeister的答案正是我所寻找的,但为了清楚地了解与问题相关的一切,最新版本的abaqus远远落后于最新版本的python。 Abaqus currently uses python 2.6, which means argparse is not available. Abaqus目前使用python 2.6,这意味着argparse不可用。 I had to switch to using the deprecated optparse library. 我不得不切换到使用已弃用的optparse库。 Luckily the difference between the two was minor. 幸运的是,两者之间的差异很小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM