EvgenAbaqus
Mechanical
- Jan 27, 2015
- 17
Hi there!
I have a script which can write *.csv file with name lets say 1.csv
I'm going to preform parametric study, so ODB name will be same.
If do so script will just overwrite my 1.csv file and that's it.
How to change a script so it will check existed name (number) and add +1 instead overwriting
so it will write files like this:
1.csv
2.csv
...
n+1.csv
jobName = '''DOE'''
stepName = '''Step-1'''
outputSetName = '''SET-1'''
from odbAccess import*
from abaqusConstants import*
import string
import numpy as np
import os
import datetime
odb = openOdb(path = jobName+'.odb')
outfile = open('C:/DOE/1' + '.csv', 'w')
for fm in range(0, len(odb.steps[stepName].frames)):
timeFrame = odb.steps[stepName].frames[fm]
readNode = odb.rootAssembly.nodeSets[outputSetName.upper()]
Disp = timeFrame.fieldOutputs['U']
ReForce = timeFrame.fieldOutputs['RF']
readNodeDisp = Disp.getSubset(region=readNode)
readNodeDispValues = readNodeDisp.values
readNodeRF = ReForce.getSubset(region=readNode)
readNodeRFValues = readNodeRF.values
Displacement = np.zeros(len(odb.steps[stepName].frames))
ReactionForce = np.zeros(len(odb.steps[stepName].frames))
Displacement[fm] = readNodeDispValues[0].data[1] # 0-X Direction; 1-Y Direction; 2-Z Direction
ReactionForce[fm] = readNodeRFValues[0].data[1]
outfile.write(str(Displacement[fm]) + ',' + str(ReactionForce[fm]) + ',' + '\n')
outfile.close()
odb.close()
Attached ODB file:
I have a script which can write *.csv file with name lets say 1.csv
I'm going to preform parametric study, so ODB name will be same.
If do so script will just overwrite my 1.csv file and that's it.
How to change a script so it will check existed name (number) and add +1 instead overwriting
so it will write files like this:
1.csv
2.csv
...
n+1.csv
jobName = '''DOE'''
stepName = '''Step-1'''
outputSetName = '''SET-1'''
from odbAccess import*
from abaqusConstants import*
import string
import numpy as np
import os
import datetime
odb = openOdb(path = jobName+'.odb')
outfile = open('C:/DOE/1' + '.csv', 'w')
for fm in range(0, len(odb.steps[stepName].frames)):
timeFrame = odb.steps[stepName].frames[fm]
readNode = odb.rootAssembly.nodeSets[outputSetName.upper()]
Disp = timeFrame.fieldOutputs['U']
ReForce = timeFrame.fieldOutputs['RF']
readNodeDisp = Disp.getSubset(region=readNode)
readNodeDispValues = readNodeDisp.values
readNodeRF = ReForce.getSubset(region=readNode)
readNodeRFValues = readNodeRF.values
Displacement = np.zeros(len(odb.steps[stepName].frames))
ReactionForce = np.zeros(len(odb.steps[stepName].frames))
Displacement[fm] = readNodeDispValues[0].data[1] # 0-X Direction; 1-Y Direction; 2-Z Direction
ReactionForce[fm] = readNodeRFValues[0].data[1]
outfile.write(str(Displacement[fm]) + ',' + str(ReactionForce[fm]) + ',' + '\n')
outfile.close()
odb.close()
Attached ODB file: