简体   繁体   English

在 Abaqus 中导入 .inp 模型时出现“未定义关键字”错误

[英]“No Keywords Defined” Error in Importing .inp model in Abaqus

I'm having some issues when I import .inp models into Abaqus CAE.我在将.inp模型导入 Abaqus CAE 时遇到了一些问题。 I defined this new input file starting from an original input file, and changing the values of some parameters via a Python loop that works fine and produces the new .inp I need.我从原始输入文件开始定义了这个新输入文件,并通过 Python 循环更改了一些参数的值,该循环工作正常并生成我需要的新.inp

The fact is that when I try to import the new input files into CAE, it doesn't work and the error NoKeywordsDefinedError appears.事实是,当我尝试将新输入文件导入 CAE 时,它不起作用并出现错误 NoKeywordsDefinedError。 The funny fact is that if I copy and paste the content of the new .inp file into the old one, and I import that model, well, it works.有趣的事实是,如果我将新.inp文件的内容复制并粘贴到旧文件中,然后导入该模型,那么,它就可以工作了。

I defined the new .inp using in this way:我以这种方式定义了新的.inp

inputFile=open('Job-1.inp','r')
outputFile=open('ModifiedInput'+'_RUN'+str(run)+'_LEVEL'+str(r)+'.inp','w')
number_of_lines = 0
for line in inputFile:
    line = line.strip("\n")
    number_of_lines += 1
    if number_of_lines == XXX:
        line = line.replace('old','new')
        outputFile.write(line)

Maybe I should specify something when I write the lines into the new file?也许我应该在将行写入新文件时指定一些内容?

A few things you could do to improve your script:您可以做一些事情来改进您的脚本:

  1. Don't strip the new line character, unless you plan on adding it back.不要删除新行字符,除非您打算重新添加它。 When you strip it and then write the text back without the new line character all of your output will end up on a single line.当您剥离它然后在没有换行符的情况下写回文本时,您的所有输出都将在一行中结束。
  2. I am assuming you also want to write out lines that you don't modify, so move your outputFile.write statement outside of the number_of_lines check.我假设您还想写出您不修改的行,因此将outputFile.write语句移到number_of_lines检查之外。
  3. Close your file at the end of the script to make sure the written contents are flushed.在脚本末尾关闭文件以确保写入的内容已刷新。

inputFile=open('Job-1.inp','r')
outputFile=open('ModifiedInput'+'_RUN'+str(run)+'_LEVEL'+str(r)+'.inp','w')
number_of_lines = 0

for line in inputFile:
    #line = line.strip("\n")
    number_of_lines += 1
    if number_of_lines == XXX:
        line = line.replace('old','new')
    outputFile.write(line)

inputFile.close()
outputFile.close()

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

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