简体   繁体   中英

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

I'm having some issues when I import .inp models into 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.

The fact is that when I try to import the new input files into CAE, it doesn't work and the error NoKeywordsDefinedError appears. 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.

I defined the new .inp using in this way:

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.
  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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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