示例#1
0
def open_odb(odb_path):
    """
    A more sophisticated open odb function.

    Parameters
    ----------
    odb_path : string
        Path and filename of the database (without the '.odb' extension)

    Attributes
    ----------

    Notes
    -----

    References
    ----------

    """

    base, ext = os.path.splitext(odb_path)
    odb_path = base + '.odb'
    if odbAccess.isUpgradeRequiredForOdb(upgradeRequiredOdbPath=odb_path):
        print('odb %s needs upgrading' % (odb_path,))
        path, file_name = os.path.split(odb_path)
        file_name = base + "_upgraded.odb"
        new_odb_path = os.path.join(path, file_name)
        odbAccess.upgradeOdb(existingOdbPath=odb_path, upgradedOdbPath=new_odb_path)
        odb_path = new_odb_path
    odb = odbAccess.openOdb(path=odb_path, readOnly=True)
    return odb
示例#2
0
def odbs_upgrade_odbs_folder(odbs_folder, recursive=False, print_every=1):
    """
    Upgrades all Odb objects in odb_folder to current Abaqus CAE version.
    Inputs: odbs_folder. Folder to fetch Odb objects from.
            recursive. Boolean, if True, search for Odb objects recursively.
            print_every. Int that defines intervals for printing info.
    """
    import odbAccess
    odb_list = files_with_extension_lister(odbs_folder,
                                           '.odb',
                                           full_name_option=True,
                                           sub_folders_option=recursive)
    upgradable_odb_list = [
        i for i in odb_list if odbAccess.isUpgradeRequiredForOdb(i)
    ]
    print(len(odb_list), 'Odb objects found', len(upgradable_odb_list),
          'require upgrade')
    temp_name = os.path.join(odbs_folder, 'temp_odb_name.odb')
    for job_number, job_key in enumerate(upgradable_odb_list):
        # Option to print less
        if divmod(job_number, print_every)[1] == 0:
            print('Processing', job_key, job_number + 1, 'of',
                  len(upgradable_odb_list))
        new_name = job_key
        old_name = job_key.replace('.odb', '-old.odb')
        session.upgradeOdb(job_key, temp_name)
        # Rename old and new Odb files
        os.rename(job_key, old_name)
        os.rename(temp_name, new_name)
    print('DONE')
    return
示例#3
0
 def upgrade_if_necessary(filename):
     if isUpgradeRequiredForOdb(upgradeRequiredOdbPath=filename):
         oldf = filename
         dirname, basename = split(filename)
         root, ext = splitext(basename)
         basename = root + "_upgraded" + ext
         filename = join(dirname, basename)
         upgradeOdb(existingOdbPath=oldf, upgradedOdbPath=filename)
     return filename
示例#4
0
    def __init__(self, odbname1):
        """this is executed with the object is instantiated"""
        # odbname1 = 'C:/Users/ngordon/Desktop/abaqus-scripting/customBeamExample/customBeamExample.odb'

        if ' ' in odbname1:
            print('Remove all spaces from file path %s' % odbname1)
            sys.exit(0)
        else:
            if odbAccess.isUpgradeRequiredForOdb(
                    upgradeRequiredOdbPath=odbname1):
                newodb = odbname1.name.replace('.odb', '_new.odb')
                odbAccess.upgradeOdb(existingOdbPath=odbname,
                                     upgradedOdbPath=newodb)
                odbname1 = newodb

            self.myOdbDat = session.openOdb(name=odbname1, readOnly=True)
            self.myAssembly = self.myOdbDat.rootAssembly

        self.xyp = session.XYPlot(name='XYPlot-1')
        ## can be run multiple times but the line >>>session.xyPlots['XYPlot-1'] , can only be run once >>>ession.XYPlot('XYPlot-1')
        chartName = self.xyp.charts.keys()[0]
        self.chart = self.xyp.charts[chartName]
        # self.chart.legend.textStyle.setValues(font='-*-verdana-medium-r-normal-*-*-340-*-*-p-*-*-*')
        self.chart.legend.setValues(show=False)
        self.chart.legend.titleStyle.setValues(
            font='-*-verdana-medium-r-normal-*-*-240-*-*-p-*-*-*')
        self.chart.gridArea.style.setValues(fill=False)
        self.xyp.title.style.setValues(
            font='-*-arial-medium-r-normal-*-*-240-*-*-p-*-*-*')

        # 30 <= width <= 423           30 <= height <= 564
        self.myVp = session.Viewport(name='myVp1',
                                     origin=(0, 0),
                                     width=400,
                                     height=550)
        self.myVp.setValues(displayedObject=self.myOdbDat)

        self.csysCyn = self.myOdbDat.rootAssembly.DatumCsysByThreePoints(
            name='CSYS-CYN',
            coordSysType=CYLINDRICAL,
            origin=(0.0, 0.0, 0.0),
            point1=(1.0, 0.0, 0.0),
            point2=(0.0, 1.0, 0.0))

        # default view
        self.myView = 'Iso'
        # session settings
        session.printOptions.setValues(vpBackground=OFF,
                                       rendition=COLOR,
                                       vpDecorations=FALSE,
                                       compass=OFF)
        session.psOptions.setValues(orientation=LANDSCAPE)
        session.pageSetupOptions.setValues(imageSize=SIZE_ON_SCREEN,
                                           quality=FINE,
                                           orientation=LANDSCAPE,
                                           logo=OFF)
def safeOpenOdb(odb_path):
    # upgrade odb if required (original simulation executed in older abaq. version)
    if isUpgradeRequiredForOdb(odb_path):
        upgradeOdb(odb_path, odb_path + '_')
        shutil.move(odb_path + '_.odb', odb_path)
    try:
        odb = openOdb(odb_path)
    except OdbError, e:
        print str(e)
        exit(1)
示例#6
0
def open_odb(odbPath):
    base, ext = os.path.splitext(odbPath)
    odbPath = base + '.odb'
    new_odbPath = None
    if odbAccess.isUpgradeRequiredForOdb(upgradeRequiredOdbPath=odbPath):
        print('odb %s needs upgrading' % (odbPath, ))
        path, file_name = os.path.split(odbPath)
        file_name = base + "_upgraded.odb"
        new_odbPath = os.path.join(path, file_name)
        odbAccess.upgradeOdb(existingOdbPath=odbPath,
                             upgradedOdbPath=new_odbPath)
        odbPath = new_odbPath
    odb = odbAccess.openOdb(path=odbPath, readOnly=True)
    return odb
示例#7
0
文件: abaqus.py 项目: nagordon/mechpy
    def __init__(self, odbname1):
        """this is executed with the object is instantiated"""
        # odbname1 = 'C:/Users/ngordon/Desktop/abaqus-scripting/customBeamExample/customBeamExample.odb'

        if ' ' in odbname1:
            print('Remove all spaces from file path %s' % odbname1)
            sys.exit(0)
        else:
            if odbAccess.isUpgradeRequiredForOdb(upgradeRequiredOdbPath=odbname1):
                newodb = odbname1.name.replace('.odb','_new.odb')
                odbAccess.upgradeOdb(existingOdbPath=odbname, upgradedOdbPath=newodb)
                odbname1 = newodb

            self.myOdbDat =  session.openOdb(name=odbname1, readOnly=True)
            self.myAssembly = self.myOdbDat.rootAssembly

        self.xyp = session.XYPlot(name='XYPlot-1')
        ## can be run multiple times but the line >>>session.xyPlots['XYPlot-1'] , can only be run once >>>ession.XYPlot('XYPlot-1')
        chartName = self.xyp.charts.keys()[0]
        self.chart = self.xyp.charts[chartName]
        # self.chart.legend.textStyle.setValues(font='-*-verdana-medium-r-normal-*-*-340-*-*-p-*-*-*')
        self.chart.legend.setValues(show=False)
        self.chart.legend.titleStyle.setValues(font='-*-verdana-medium-r-normal-*-*-240-*-*-p-*-*-*')
        self.chart.gridArea.style.setValues(fill=False)
        self.xyp.title.style.setValues(font='-*-arial-medium-r-normal-*-*-240-*-*-p-*-*-*')

                        # 30 <= width <= 423           30 <= height <= 564
        self.myVp = session.Viewport(name='myVp1', origin=(0, 0), width=400, height=550)
        self.myVp.setValues(displayedObject=self.myOdbDat)

        self.csysCyn = self.myOdbDat.rootAssembly.DatumCsysByThreePoints(name='CSYS-CYN',
                                                            coordSysType=CYLINDRICAL,
                                                            origin=(0.0, 0.0, 0.0), point1=(1.0, 0.0,
                                                            0.0), point2=(0.0, 1.0, 0.0))

        # default view
        self.myView = 'Iso'
        # session settings
        session.printOptions.setValues(vpBackground=OFF,
                                       rendition=COLOR,
                                       vpDecorations=FALSE,
                                       compass=OFF)
        session.psOptions.setValues(orientation=LANDSCAPE)
        session.pageSetupOptions.setValues(imageSize=SIZE_ON_SCREEN,
                                           quality=FINE,
                                           orientation=LANDSCAPE,
                                           logo=OFF)
示例#8
0
def upgrade_odbs_folder(odbs_folder, recursive=False, print_every=1):
    """Upgrade version of all Odb objects in a folder.

    Parameters
    ----------
    odbs_folder : Path
        Folder containing Odb objects.
    recursive : bool, optional
        If True, list Odb files recursively, including subfolders.
    print_every : int, optional
        If given, reduces printing reports frequency.

    Returns
    -------
    None
    """
    # List Odb paths, filter only old versioned and report.
    odb_list = ft.list_files_with_extension(odbs_folder, '.odb', 1, recursive)
    upgradable_odb_list = [
        i for i in odb_list if odbAccess.isUpgradeRequiredForOdb(i)
    ]
    print(len(odb_list), 'Odb objects found', len(upgradable_odb_list),
          'require upgrade')

    # Set temporary names and iterate over old versioned Odbs.
    temp_name = os.path.join(odbs_folder, 'temp_odb_name.odb')
    for job_number, job_key in enumerate(upgradable_odb_list):

        # Optionally, report less times.
        if divmod(job_number, print_every)[1] == 0:
            print('Processing', job_key, job_number + 1, 'of',
                  len(upgradable_odb_list))

        # Upgrade and rename new and old Odb files.
        new_name = job_key
        old_name = job_key.replace('.odb', '-old.odb')
        session.upgradeOdb(job_key, temp_name)
        os.rename(job_key, old_name)
        os.rename(temp_name, new_name)
    print('DONE')
    return
示例#9
0

# argparse seems not to work here (first arguments are abaqus internals)
odb_path = sys.argv[-2]
png_path = sys.argv[-1]

# Create a viewport for this example.

myViewport = session.Viewport(name='State Plot',
                              origin=(0, 0),
                              width=250,
                              height=200)
SetContourRange(0, 800, vp='State Plot')

# upgrade odb if required (original simulation executed in older abaq. version)
if isUpgradeRequiredForOdb(odb_path):
    upgradeOdb(odb_path, odb_path + '_')
    shutil.move(odb_path + '_.odb', odb_path)

# Open the output database and associate it with the viewport.
# Then set the plot state to CONTOURS_ON_DEF
try:
    odb = visualization.openOdb(path=odb_path)

except (AbaqusException), e:
    print 'Abaqus Exception:', e

myViewport.setValues(displayedObject=odb)

myViewport.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF, ))