0

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)
Luc Rebillout
  • 11
  • 1
  • 6

3 Answers3

0

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.

hgazibara
  • 1,832
  • 1
  • 19
  • 22
  • Thank you for those comments. I don't have Abaqus right now to give you the exact answer but the code usually stops at the beginning of the loop and the error goes : "Error line ### in ?" Also I've left those bits of code with the `import __name__` fragment because it was already in the abaqusMacros python file. I don't use File > Run Script to run that code, I just open the Macro Manager and hit "Run". I'll try to solve those identation issues.. Other comments or remarks are of course welcomed ! – Luc Rebillout Jan 23 '15 at 18:22
  • When you're able to run Abaqus again, definitely post the actual error. There is also a possible problem because variable `odbFile` doesn't seem to be declared. – hgazibara Jan 23 '15 at 18:24
  • True, I just started looking into macros and python today so I'm a bit lost. I thought tweaking the macro just a little bit would be failry easy. – Luc Rebillout Jan 23 '15 at 18:30
  • I think only the `stepsName` line is incorrectly indented. I'd be willing to bet that isnt the real issue, but something that happend when you pasted to this site. Fixing that makes everything else part of the `vonMimises` def. The function gets called from the gui when you invoke the macro. – agentp Jan 23 '15 at 19:50
  • If I can I'll try this out tomorrow. I'll let you guys know how it goes, thank you! – Luc Rebillout Jan 23 '15 at 20:31
0

Got it :

I'll use the code posted above, repeated here :

# -*- 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)

And I just discovered the "Excel Utilities" tool on Abaqus which is enough for what I want to do.

Thanks y'all for your input.

Luc Rebillout
  • 11
  • 1
  • 6
0

Here is how you extract XY-data

from odbAccess import *        


odb = session.odbs['C:/Job-Directory/Job-1.odb']        
output = open('Result.dat', 'w')        

for i in range (0,Number-of-XYData-to-extract):        
    xy1 = odb.userData.xyDataObjects['XYData-'+str(i)]        
    for x in range (0,len(xy1)):        
        output.write ( str(xy1[x]) + "\n" )        
output.close()