How to use Run Command block

Question:

Learn how to use the Run Command block

Answer:

The Run Command (Beta) block allows you to run any command-line command directly within nTop. This block enables the execution of diverse external processes, such as executing complex simulations, interfacing with external design tools, or integrating manufacturing processes. The following examples are the common use cases:

  • Connecting applications: Any command line executables of design, analysis, or manufacturing software and tools
  • Automation: Execute Command Line or PowerShell commands for automation.
  • Scripting: Execute commands in Python, Lua, or any other scripting language you choose.

Notes on receiving technical support

When requesting help with the Run Command block, please note that:

  • We can't open any of your script files on our end, so please don't send any script files as an attachment or link when opening a support ticket.
  • We can’t debug any of the scripts you have written.
  • We can't run your workflow that has a 'Run Command' block on our end.

Tips

1. Permission Setting for Run Command blocks.

    • Prompt per file: each time you create or open a file that contains run commands, you will be prompted to trust the file.
      • This is helpful when you have many Run Command blocks in your file or use list processing because trusting the file will allow everything to run.
      • Once you trust a file, all future changes and additional Run Command blocks will be trusted.
      • This option is less secure because you cannot pick specific Run Commands to trust.
    • Prompt per block: each time a Run Command block tries to run, you will be prompted to trust that instance to run.
      • This default setting gives you the most control over Run Command blocks in your file.
      • This setting is less convenient when you have several Run Command blocks or list-processing because you will be prompted many times.
    • Disallow all: all Run Command blocks will not be able to run, and you will not be prompted.
      • This is the most secure setting.
  • Note:
    • Changing the permission setting will require you to close and reopen nTop.
    • The trust settings are saved for the duration of your session. This means if you trust a file and then close and reopen that file later, you will be asked to trust the file again.
    • When using Run Command, the Trust Settings for nTopCL can be passed with the --trustNotebook option.
ntopcl --trustNotebook [nTop Notebook Path]

2. Working Directory Input

  • The Working Directory input lets you set a relative directory dynamically associated with the process.
  • Note: The default Working Directory is not where your file is located. It is the directory of the parent process.  This means the default directory depends on how nTop is opened; opening nTop from the standard installation will result in the directory "C:\Program Files\nTopology\nTopology\".  This will differ if you open or execute the nTop Notebook via PowerShell. Running an external process through the default nTop directory could lead to library collisions.
  • If you happen to experience library collisions, please manually set a Working Directory.

Examples:

1. Getting files from a directory (Powershell Commands)

We will run the PowerShell command through the Run Command block for this example. The PowerShell command returns all the files in a directory.

Powershell ‘Get-ChildItem -Name <directory>’

We will recreate the command using a combination of the Concatenate Text blocks and File Path variables. 

Files in Directory.ntop

This custom block returns all the file paths of a specific file type in a directory. To use this block, select one reference file, and the block will use the parent folder. The output of the PowerShell cmdlet is then filtered and parsed using blocks. We can save the entire workflow as a Custom block (How to create a custom block) and import it to return all files.

Example File

2. Plotting CSV results with Python

We will run a Python script through the Run Command block for this example. We will be parsing data to Python in two methods.

Before we start, ensure you have Python, Matplotlib and the Pandas library installed.

1. Command-line arguments

  • This works best with fewer inputs like file paths, scalars, etc. In this example, we will parse the headers and plot type as command-line arguments.

2. Temporary Files

  • This is to be used when you have many variables, long lists, etc. We will use a .csv export created using the Export Table block.

We have a Python script that takes in input CSV, X-Axis Header, Y-Axis Header, and Plot Type as input.

python ./Plot.py ./Result.csv Mode Eigenfrequencies Bar

We will recreate the command using a combination of the Concatenate Text blocks and File Path variables. 

2D Plot.ntop

This custom block runs the Python script and our selected CSV file and header. To use this block, select the correct inputs. The output of the command is a resultant Python window with the plot.

Example File

3. nTop <>Fluent 

We will generate an FE Mesh, export it to Ansys Fluent, and then import the CFD Results back. This example briefly explains the steps involved in exporting, importing, and parsing data between nTop and Ansys. 

I recommend you check our How to export your design to Ansys Fluent article to learn more about preparing your model for Ansys Fluent.

This example uses an Await block that lets you pause and await a block completion before running the Run Command Block.

  • The Await block contains two input variables of Any type to facilitate this synchronization. The first input, Await, is for the block awaiting completion. The second input, Return, is the output once the Await is completed.

We will use a .jou command file for Fluent Call. Once the FE Mesh is generated, we will Delete All Files. The next step is to export the CFD Mesh with Boundaries (How to create CFD Boundaries).

Once the FE Mesh is exported and the Fluent is run, we will import the results using another Await block and Import CFD Analysis Result block.

Example File

Was this article helpful?