我需要一种算法来更新输入文件,发现可以修改.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窗口,但不适用于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/

10-12 19:50