Altair Compose® Challenge #2: Batch calling OML scripts

RSGarciarivas
RSGarciarivas
Altair Employee
edited August 2023 in Altair HyperWorks

Altair Compose is a powerful engineering math toolbox and you can script inside it to make your work more efficient. However, to fully master Compose, you must know how to incorporate it into your workflows even without its user interface and, more importantly, be able to leverage its capabilities regardless of it being your primary tool or just assisting in specific tasks.

Today, we will explore how you can call Compose to run scripts from the Command Prompt without opening Compose, which is a very important part of any worthwhile automation workflow. Imagine you need to run a simulation hundreds of times and, for each output produced, you need to process it and send it to another tool for subsequent simulation, running Compose in batch from the Command Console would be perfect for this.

Compose installations contain the file Compose_batch.bat, located at [your Compose install location]\hwx. This is the way for us to call Compose externally.

Open the Command Terminal and type this (substituting for your own installation path and example file location):

"C:\Program Files\Altair\2022.3\Compose2022.3\hwx\Compose_batch.bat" -f "C:\Users\rsanchez\Documents\Knowledge Base\Community Challenges\3. Compose - Batch calling OML scripts\OML batch call example.oml" -input [1 2 3] “string input” 34

If executed properly, the following messages will echo in the command prompt:

Number of inputs: 3

First input: [1 2 3]

image

Have a look at this script from Compose so you can get a good understanding of how it works. Your challenge is to write an OML script that can be executed in batch and receives two inputs from the user:

  1. A .txt file name
  2. A message to print in the .txt file

A .txt file matching the desired name must be created and the message must be printed into it. Like this:

image

Some things to keep in mind when creating scripts for batch execution:

  • You won’t be prompted to change the working directory prior to running a script, so set your paths accordingly. cd(fileparts(omlfilename('fullpath'))); can be used to change it to the script’s location.
  • Commands getcmdinput, getnumofcmdinputs, etc. are essential OML script batch calls.
  • Always test your scripts in the GUI before you take them intro the Command Prompt, so you can debug efficiently, if needed.

Don’t forget to look at OML batch call example.oml for a head start. Have a look at functions fopen, fprintf and fclose for writing the output file.

Level: Medium

Product Required: Compose 2020 or later version (including Personal Edition)

The solution can be attached in the comment section of this post. The desired output format is a picture of the script call in the Command Prompt and the file contents, like the one shown.

The solution to Challenge Signal based modelling of a mass-spring-damper system can be found here.

If you would like to solve more challenges and get regular challenge release updates, Subscribe to the Altair Community Challenge forum.

Edit: The solution to this challenge has been attached as another script. Try to solve it on your own before looking at it!