python script for saving subsequent images without overwriting
Question: I am new to python but I have been able to make a script (pls see code below
and attached picture ) that accesses abaqus .odb output file and saves the
contour map as a .tiff file. Since this script runs at interval, the new image
file overwrites the previous but I actually want to save the subsequent images
with different name e.g. VMises_01, VMises_02, VMises_03, etc. Please i need
asssistance in modifying the script to do this. Thank you in advance for your
help.

    
    
    # -*- coding: mbcs -*-
    from abaqus import *
    from abaqusConstants import *
    session.Viewport(name='Viewport: 1', origin=(0.0, 0.0), width=153.191665649414, 
     height=265.695220947266)
    session.viewports['Viewport: 1'].makeCurrent()
    session.viewports['Viewport: 1'].maximize()
    from caeModules import *![enter image description here][1]
    from driverUtils import executeOnCaeStartup
    executeOnCaeStartup()
    session.viewports['Viewport: 1'].partDisplay.geometryOptions.setValues(
     referenceRepresentation=ON)
    Mdb()
    session.viewports['Viewport: 1'].setValues(displayedObject=None)
    import os
    os.chdir(r"C:\Work\2015 CA")
    o1 = session.openOdb(name='C:/Work/2015 CA/cafe_del.odb')
    session.viewports['Viewport: 1'].setValues(displayedObject=o1)
    session.viewports['Viewport: 1'].odbDisplay.display.setValues(plotState=(
     CONTOURS_ON_DEF, ))
    session.viewports['Viewport: 1'].odbDisplay.commonOptions.setValues(
     visibleEdges=FEATURE, deformationScaling=UNIFORM, uniformScaleFactor=1)
    session.printToFile(fileName='C:/Work/2015 CA/VMises_01', format=TIFF, 
     canvasObjects=(session.viewports['Viewport: 1'], ))
    session.odbs['C:/Work/2015 CA/cafe_del.odb'].close()
    


Answer: One simple way of getting a unique filename would be to append a timestamp.

e.g. replace

    
    
    session.printToFile(
      fileName='C:/Work/2015 CA/VMises_01', 
      format=TIFF, 
      canvasObjects=(session.viewports['Viewport: 1'], ))
    

with

    
    
    session.printToFile(
      fileName='C:/Work/2015 CA/VMises_%s' % datetime.datetime.now().strftime('%Y%d%m%H%M%S') , 
      format=TIFF, 
      canvasObjects=(session.viewports['Viewport: 1'], ))
    

If instead you want the counter 01, 02, 03, etc, that you proposed, then
you'll either need to (a) keep a record of the current number within the
script (either in memory or to disk if the script doesn't run continuously),
or (b) look at the directory contents to determine the next available number
each time.

