Using Process Utilities

ACT process utility capabilities enable you to execute any outside program with a single method call. To do this, you call the method Start exposed on the object ExtAPI.ProcessUtils.

The following APIs are available:

ClassMemberDescription

ExtAPI.ProcessUtils

Start(target, args)

Starts an application, file, or other target. Returns an integer error code from the resulting process. Waits for process to exit.

Start(target, useShell, args)

Starts an application, file, or other target. useShell indicates whether or not to use the running OS’s shell to execute the target.

A sample implementation of process utilities follows.

import System

def update(task):
    activeDir = task.ActiveDirectory
    extensionDir = task.Extension.InstallDir
    exeName = "ExampleAddinExternalSolver.exe"
    solverPath = System.IO.Path.Combine(extensionDir, exeName)
    
    inputValue = task.Properties["Inputs"].Properties["Input"].Value
    
    inputFileName = "input.txt"
    outputFileName = "output.txt"
    dpInputFile = System.IO.Path.Combine(activeDir, inputFileName)
    dpOutputFile = System.IO.Path.Combine(activeDir, outputFileName)
    
    #write input file
    f = open(dpInputFile, "w")
    f.write('input='+inputValue.ToString(
             System.Globalization.NumberFormatInfo.InvariantInfo))
    f.close()
    
    exitCode = ExtAPI.ProcessUtils.RunApplication(solverPath, 
                                                  dpInputFile, dpOutputFile)
    if exitCode != 0:
        raise Exception ('External solver failed!')
    #read output file
    
    outputValue = None
    f = open(dpOutputFile, "r")
    currLine = f.readline()
    while currLine != "":
        valuePair = currLine.split('=')
        outputValue = System.Double.Parse(valuePair[1], 
                        System.Globalization.NumberFormatInfo.InvariantInfo)
        currLine = f.readline()
    f.close()
    
    if outputValue == None:
        raise Exception("Error in update - no output value detected!")
    else:
        task.Properties["Outputs"].Properties["Output"].Value = outputValue

Release 18.2 - © ANSYS, Inc. All rights reserved.