Search code examples
abaqus

How to create a material orientation using Abaqus python API - datums issue


I am working on a software package that allows me to programmatically sweep through different geometries for a cylinder-like part, and both because my material is anisotropic and because it makes data analysis easier for my geometry, I need to define a cylindrical coordinate system csys_cyl for each generated part and then assign it as a material orientation. While I can easily do this in the GUI, the API is giving me one specific issue: when assigning the material orientation, I cannot actually use the csys I generate as the localCsys argument to the materialOrientation function. Instead, I have to use the below code, where I simply call the entry in datums that I got from the .jnl file I generated when using the GUI. Is there a better way to pass that localCsys argument that doesn't depend on a hard-coded ID number?

csys_cyl = part.DatumCsysByThreePoints(
    coordSysType=CYLINDRICAL, name='csys_cyl', origin=(0.0, 0.0, 0.0), point1=(
    0.0, -1.0, 0.0), point2=(1.0, 0.0, 0.0))
part.MaterialOrientation(
    additionalRotationField='', additionalRotationType=ROTATION_NONE, angle=0.0,
    axis=AXIS_3, fieldName='',
    localCsys=part.datums[2], # what I'm forced to do
    # localCsys=csys_cyl, # what I would really like to do
    orientationType=SYSTEM,
    region=Region(cells=part.cells), stackDirection=STACK_3)

Solution

  • I found the most effective solution was to use the id attribute of the csys object I generated. After interrogating variables, it seems that csys_cyl, the object returned by DatumCsysByThreePoints is just a generic feature, as is the object returned by Anbu's answer.

    >>> print(csys_cyl)
    ({'children': '', 'id': 2, 'isOutOfDate': False, 'name': 'csys_cyl', 'parents': '', 'path': 'unknown', 'sketch': 'unknown'})
    

    In contrast, the object returned from the datums dictionary is a specific DatumCsys type.

    >>> print(part.datums[csys_cyl.id])
    ({'axis1': 'DatumAxis object', 'axis2': 'DatumAxis object', 'axis3': 'DatumAxis object', 'coordSysType': CYLINDRICAL, 'origin': 'DatumPoint object', 'pointOn': (0.0, 0.0, 0.0)})
    

    Thus I found the solution to be using the id attribute of csys_cyl to get the DatumCsys from the dictionary, as shown below:

    def add_cyl_csys(part):
        ###################################
        ## ADD CSYS AND MATERIAL ORIENTATIONS
        ###################################
        csys_cyl = part.DatumCsysByThreePoints(
            coordSysType=CYLINDRICAL, name='csys_cyl', origin=(0.0, 0.0, 0.0), point1=(
            0.0, -1.0, 0.0), point2=(1.0, 0.0, 0.0))
        part.MaterialOrientation(
            additionalRotationField='', additionalRotationType=ROTATION_NONE, angle=0.0,
            axis=AXIS_3, fieldName='',
            localCsys=part.datums[csys_cyl.id],
            orientationType=SYSTEM,
            region=Region(cells=part.cells), stackDirection=STACK_3)