Skip to main content

Introduction

This example demonstrates how to use the Granta MI JobQueue library with the Scripting Toolkit. The JobQueue library replaces the AsyncJobQueue component previously available within the MI Scripting Toolkit, and allows interaction with the Granta MI Job Queue via Python. The JobQueue library supports import and export operations. This example demonstrates how to use the MI Scripting Toolkit to define the records exported to Excel using an Excel template. This example does not cover all aspects of the JobQueue package. Full API documentation and additional examples are available here.
Info:Running this notebook requires the ansys-grantami-jobqueue package. See the ‘PyGranta Dependencies’ section of the ‘Example Notebooks’ documentation page for more details.

Define the records to export

First create an MI Scripting Toolkit session.
Next, access all records in a specific tree location. We will need the database key later, so store it in a constant.
Previous cell output:

Create an ‘ansys-grantami-jobqueue’ client

Use the Connection class to connect to create a JobQueue client.
Previous cell output:

Export the records to Excel

All JobQueue operations are performed by first creating a JobRequest object, and then submitting that object to the server. An ExcelExportJobRequest object requires the following:
  • A name and description
  • The path to an Excel export template, provided as either a string or a pathlib.Path object
  • A list of ExportRecord objects, which contain a record history identity and optionally a record version
  • The database key for the provided ExportRecord objects
First, create the list of ExportRecord objects from the list of Record objects.
Previous cell output:
Next, create the Excel export request.
Previous cell output:
Finally, use the JobQueue.create_job_and_wait method to submit the ExcelExportJobRequest object to the server. This method returns once the job is complete.
Previous cell output:

Access the exported data

Once the job is complete, the list of files generated as part of the operation can be accessed via the output_file_names property.
Previous cell output:
The binary content of an individual file can be accessed with the get_file_content method, or alternatively the file can be saved to disk with the download_file method. See the JobQueue API documentation for a demonstration of these methods.