gpt4 book ai didi

python - 交互 python 和 abaqus

转载 作者:太空宇宙 更新时间:2023-11-03 16:10:07 24 4
gpt4 key购买 nike

我需要一种算法来更新输入文件,我发现我可以修改 .py 文件并在 abaqus 中运行它。

但是由于该过程需要自动化,我正在尝试打开一个脚本并在 abaqus 中运行它

我尝试了这个:os.system('abaqus cae script=C:\Users\Samuel\abaqus-1\script1.py')

import os
import subprocess


HERE = os.path.dirname(os.path.abspath(__file__))


def create_script(name):
path = os.path.join(HERE, 'abaqus-1', name)
return path


name = 'script1.py'
script_path = create_script(name)
print (script_path)


args = ['abaqus', 'cae', 'script={0}'.format(script_path)]
print (args)
p = subprocess.Popen(args) # Success!
print(p.communicate())

这适用于 cmd dos windows,但不适用于 python,如果有人可以帮助我,我将不胜感激

错误

['abaqus', 'cae', 'script=C:\\Users\\Samuel\\abaqus-1\\script1.py']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Samuel\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile
execfile(filename, namespace)
File "C:\Users\Samuel\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Samuel/prueba control.py", line 28, in <module>
p = subprocess.Popen(args) # Success!
File "C:\Users\Samuel\Anaconda3\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Users\Samuel\Anaconda3\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

最佳答案

也许这句话是不正确的 -

os.system('abaqus cae script=C:\Users\Samuel\abaqus-1\script1.py')

您必须使用命令在 Abaqus 中运行 python 脚本

abaqus cae noGUI=nameOfScript.py

所以就你而言,

os.system('abaqus cae noGUI=C:\\Users\\Samuel\\abaqus-1\\script1.py')

我不确定“\”,因为我通常在Python脚本所在的同一文件夹中打开abaqus。

关于python - 交互 python 和 abaqus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39399635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com