pythonabaqus

abaqus error when job is created through python script due to a not defined job type name


I'm trying to create Abaqus jobs through a python script. Problem is, Abaqus is refusing to detect the job type. it keeps returning this

NameError: name 'ANALYSIS' is not defined

It creates the job fine without the type defined, but it won't accept any type. These are the modules I imported

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
import SymbolicConstant
import abaqusConstants

And this is the actual command I'm using

p1 = mdb.models[n].rootAssembly
session.viewports['Viewport: 1'].setValues(displayedObject=p1)
job=mdb.Job(name=n, model=n, description='', type=ANALYSIS, atTime=None, waitMinutes=0, waitHours=0, queue=None, memory=90,memoryUnits=PERCENTAGE, getMemoryFromAnalysis=True,explicitPrecision=SINGLE, nodalOutputPrecision=SINGLE, echoPrint=OFF, modelPrint=OFF, contactPrint=OFF, historyPrint=OFF,userSubroutine='', scratch='', resultsFormat=ODB,numThreadsPerMpiProcess=1, multiprocessingMode=DEFAULT, numCpus=4,numDomains=4, numGPUs=0)

I tried multiple job types. I tried creating the commend by recording a macro script and then running that exact macro but it still won't work. The only way I was able to create the job is without the type.


Solution

  • Usually, all the constants such as ANALYSIS, etc., are defined in the abaqusConstants Abaqus module.
    You have imported the abaqusConstants module, however, you are using the constants defined in that module. To use the constants from that module, you have use reference to that module. Simply put, you have use it as follows:

    import abaqusConstants
    
    # Use the constant from abaqusConstants using .(dot) notation
    ana_type = abaqusConstants.ANALYSIS
    

    OR
    You can use the simpler way as:

    from abaqusConstants import *
    
    # No need to give the reference to the module using .(dot) notation
    # as you have directly imported all the constants in the current namespace directly
    ana_type = ANALYSIS
    

    This option is, as you can see, easy to use as we have sometime very long Abaqus API commands. As in your code also, you have used many constants, such as ANALYSIS, PERCENTAGE, SINGLE, OFF, etc. So, if you use reference (1st option), the command will be much longer.

    You can modify your code as below (change is only in the import statements):

    from caeModules import *
    import regionToolset
    import displayGroupMdbToolset as dgm
    import xyPlot
    import displayGroupOdbToolset as dgo
    from abaqusConstants import *
    
    p1 = mdb.models[n].rootAssembly
    session.viewports['Viewport: 1'].setValues(displayedObject=p1)
    job=mdb.Job(name=n, model=n, description='', type=ANALYSIS, atTime=None,
                waitMinutes=0, waitHours=0, queue=None, memory=90,memoryUnits=PERCENTAGE,
                getMemoryFromAnalysis=True, explicitPrecision=SINGLE, nodalOutputPrecision=SINGLE,
                echoPrint=OFF, modelPrint=OFF, contactPrint=OFF, historyPrint=OFF,
                userSubroutine='', scratch='', resultsFormat=ODB, numThreadsPerMpiProcess=1,
                multiprocessingMode=DEFAULT, numCpus=4, numDomains=4, numGPUs=0)