使用abaqus python 2.6.2将变量传递到python脚本文件

2024-10-01 07:20:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过命令行将变量传递到abaqus脚本文件(.psf)。每次执行另一个脚本时都会进行命令行调用,并且每次调用中变量的值都不同。在这方面我能得到关于命令语法的帮助吗。我尝试了os.system和{},它们都给出了某种错误。在

在我的主脚本(.py文件)中,它调用.psf

Xa=150000
abaqusCall = 'abaqus script=tt_Par.psf'
runCommand = 'cmd.exe /c ' + abaqusCall
process = subprocess.Popen(runCommand, cwd=workDir, args=Xa)

psf和

它接受这种格式的变量。。在

^{pr2}$

有人能在这方面指点迷津吗?在

提前谢谢你


Tags: 文件命令行py命令脚本os错误语法
1条回答
网友
1楼 · 发布于 2024-10-01 07:20:19

试试这个。我不确定psf文件是什么,但我只是使用py文件。在

def abaqus_cmd(mycmd):
    ''' 
    used to execute abaqus commands in the windows OS console
    inputs : mycmd, an abaqus command
    '''
    import subprocess, sys
    try:
        retcode = subprocess.call(mycmd,shell=True)
        if retcode < 0:
            print >>sys.stderr, mycmd+"...failed during execution", -retcode
        else:
            print >>sys.stderr, mycmd+"...success"
    except OSError as e:
        print >>sys.stderr, mycmd+"...failed at execution", e

要运行一个简单的命令,请执行以下操作

^{pr2}$

传递一个变量你可以这样做

odbfile = 'test.odb'
abaqus_cmd('abaqus python odb_to_txt.py '+odbfile)

但是,这只是abaqus中的python实例,您不能在这里访问abaqus内核。要访问abaqus内核,需要像这样运行脚本。在

abaqus_cmd('abaqus cae noGUI=beamExample.py')

我不知道如何将变量传递到abaqus内核中的脚本中,请参阅我的评论

相关问题 更多 >