Unleashing the Power of Inspire Python API and Batch Mode Processing

Karthi Kandasamy
Karthi Kandasamy
Altair Employee
edited August 24 in Altair HyperWorks

Batch Mode Overview

Batch mode processing offers a streamlined way to execute scripts without the overhead of a graphical user interface (GUI), perfect for running analyses or automated tasks. For instance, you can open an CAD file, run a structure or motion analysis, and process the results.

The code should only access the data model in the hwx.inspire and hwx.inspire.motion packages and should never import any GUI packages like hwx.gui, hwx.inspire.gui, hwx.inspire.motion.gui, etc.

Below, we provide detailed instructions on using batch mode in a Windows environment.

Batch Mode Run Command

{installation directory}/hwx/bin/win64/ExecWinEnvInsp.exe -cfg -b -p Inspire -ex hwx.exe -f {absolute path to a python script}

Command Breakdown

  • {installation directory}: Replace this with the actual installation directory of your Inspire software.
  • -cfg: This optional argument ensures that control is returned only after execution completion.
  • -b: Stands for batch mode.
  • -p Inspire: Specifies the product to use.
  • -ex hwx.exe: Executes the specified executable.
  • -f {absolute path to a script}: Specifies the absolute path to your script file.

      Additional arguments, 

  • -kc: Keep open the Windows command console and write log messages into it.
  • -o {absolute path to a model file}: Opens the specified supported file.
  • -runMode SimSolid: To perform a SimSolid analysis, you need to specify runMode as SimSolid. By default, the runMode is set to OptiStruct.

For detailed list you can refer Application Startup Options (altair.com)

Example Usage

     Assuming your Inspire software is installed in C:/Program Files/Altair/2024, and script is located at C:/Scripts/my_analysis_script.py, the command would look like this:

C:/Program Files/Altair/2024/hwx/bin/win64/ExecWinEnvInsp.exe -cfg -b -p Inspire -ex hwx.exe -f C:/Scripts/my_analysis_script.py

Place the below sample code into my_analysis_script.py

# Import necessary modules: Import the required modules from the Inspire library from hwx import inspire from hwx.inspire import SimSolidAnalysis, usingUnits  from pathlib import Path  # Open the demo file: Load the demo file ThreeBlocks.stmod from the installation directory model_path = Path(inspire.__file__).parent / 'demo' / 'files' / 'ThreeBlocks.stmod' model = inspire.openFile(model_path)  # Query specific parts and pressures: Retrieve the part named Part 1 and # the pressure named Pressure 1. # To query a Part named 'Part 1' from the model part1 = model.getChild(name='Part 1')  # To query a pressure named 'Pressure 1' from the model pressure = model.getChild(name="Pressure 1")  # Construct SimSolid Analysis parameters with default options   params = SimSolidAnalysis.Params()  # Params can also be set by calling setValues params.setValues(gravity=True, inertiaRelief=False)  # Params can also be set by directly assigning the values params.runName = "ThreeBlockModified"  # Perform SimSolid Analysis with set parameters  # ignoreWarnings argument ignores the warning on the model setup if any analysis = SimSolidAnalysis(params, ignoreWarnings=True)  # Opens the results  results = analysis.openResults()  # Retrieve and print results in MMKS units: Open the results and print them in MMKS units. with usingUnits("MMKS"):     print('results:\n', results)      # To query a pressure named 'Pressure 1' from the model     pressure = model.getChild(name="Pressure 1")          # Fetch results at a specific location:     # Get the displacement at the pressure location      # and the min-max displacement values for Part 1.     displacement = results.getAtPoint(0, 'Displacement', pressure.location)     print(f"Displacement : {str(displacement)}")              # To query a Part named 'Part 1' from the model     part1 = model.getChild(name='Part 1')      # Min max for a specific result type and part     min_max_displacement = results.getMinMax(0, 'Displacement', part=part1)     print(f"MinMax value of Displacement : {str(min_max_displacement)}")          # We can also fetch the results at a particular location with Format Options     with inspire.resultsFormatOptions(formatType='legacy', showUnits=True):         minMax_legacy = results.getMinMax(0, 'Displacement', units=True)         print(f'Formatted with legacy type {minMax_legacy}')              # Format results with two decimal points: Retrieve and format the von Mises stress values      # with two decimal points and units.     with inspire.resultsFormatOptions(formatStr='%.2f', showUnits=True):         von_mises_stress = results[0]['von Mises Stress']         min_max_stress = von_mises_stress.getMinMax()         print(f'Formatted with two decimal points {von_mises_stress.formatValue(min_max_stress)}') 

 

By leveraging Inspire Python API and batch mode processing, you can enhance your workflow efficiency, automate repetitive tasks, and ensure that your scripts run smoothly without the need for manual intervention.

Happy scripting!