Write a for loop in Abaqus Macro (Python)
Question: I've been using Abaqus for a while but I'm new to macros and python script.
I'm sorry if this kind of question has already been asked, I did search on
google to see if there was a similar problem but nothing works..

My problem is the following :

I have a model in Abaqus, I've ran an analysis with 2 steps and I created a
path in it and I'd like to extract the value of the Von Mises stress along
this path for each frame of each step. Ideally I'd love to save it into an
Excel or a .txt file for easy further analysis (e.g in Matlab).

**Edit :** I solved part of the problem, my macro works and all my data is
correctly saved in the XY-Data manager.

Now I'd like to save all the "Y" data in an excel or text file and I have no
clue on how to do that. I'll keep digging but if anyone has an idea I'll take
it !

Here's the code from the abaqusMacros.py file :

    
    
    # -*- coding: mbcs -*-
    # Do not delete the following import lines
    from abaqus import *
    from abaqusConstants import *
    import __main__
    
    
    
    def VonMises():
        import section
        import regionToolset
        import displayGroupMdbToolset as dgm
        import part
        import material
        import assembly
        import step
        import interaction
        import load
        import mesh
        import optimization
        import job
        import sketch
        import visualization
        import xyPlot
        import displayGroupOdbToolset as dgo
        import connectorBehavior
    
        odbFile = session.openOdb(name='C:/Temp/Job-1.odb')
        stepsName = odbFile.steps.keys()
        for stepId in range(len(stepsName)):
                numberOfFrames = len(odbFile.steps.values()[stepId].frames)
                for frameId in range(numberOfFrames):
                        session.viewports['Viewport: 1'].odbDisplay.setPrimaryVariable(
                            variableLabel='S', outputPosition=INTEGRATION_POINT, refinement=(
                                INVARIANT, 'Mises'))
                        session.viewports['Viewport: 1'].odbDisplay.setFrame(step=stepId, frame=frameId)
                        pth = session.paths['Path-1']
                        session.XYDataFromPath(name='Step_'+str(stepId)+'_'+str(frameId), path=pth, includeIntersections=False, 
                            projectOntoMesh=False, pathStyle=PATH_POINTS, numIntervals=10, 
                            projectionTolerance=0, shape=DEFORMED, labelType=TRUE_DISTANCE)
    


Answer: First of all, your function `VonMises` contains only import statements, other
parts of the code are not properly indented, so they are outside of the
function.

Second of all, the function is never called. If you run your script using
'File > Run script', then you should call the function at the end of your
file.

There two thing seem like obvious errors, but there are some other bad things
as well.

Also, I don't see the point of writing `import __name__` at the top of your
file because I really doubt you have a module name `__name__`; Python
environment used by Abaqus probably doesn't either.

There are some other things that might be improved as well, but you should try
to fix the errors first.

If you got an actual error message from Abaqus (either in the window or in
abaqus.rpy file), it would be helpful if you posted it here.

