I am working in automate Aspen Plus simulation and post-processing of the results with Python. In order to do scale-up analysis, sensitivity studies and solving optimization problems; I have to iterate several times running the aspen simulation.

This way, I am using win32com.client to manage it. It works great, but sometimes aspen shows a pop-up windows telling that all licenses are in use, interrupting the program flow:

issue

If I close it manually the program continues working. So I am thinking in writing a script to automate this, but I do not have any clue of how to do it.

I tried to kill, terminate, send a signal, to the process. But nothing works because kill the AspenPlus.exe process, stops the program.

2 Answers

2
SingulatiryPanda On Best Solutions

Here is some sample powershell code you can use to check if the Aspen process is running and if the window is open then to close it by sending the appropriate key via the sendKey function

$isAspenOpen = Get-Process Aspen*
if($isAspenOpen = $null){
    # Aspen is already closed run code here:
    }
else {
     $isAspenOpen = Get-Process AspenPlus*

     # while loop makes sure all Aspen windows are closed before moving on to other code:
         while($isAspenOpen -ne $null){
            Get-Process aspen* | ForEach-Object {$_.CloseMainWindow() | Out-Null }
            sleep 5
            If(($isAspenOpen = Get-Process aspen*) -ne $null){
            Write-Host "Aspen is Open.......Closing Aspen"
                $wshell = new-object -com wscript.shell
                $wshell.AppActivate("Aspen Plus")
                $wshell.Sendkeys("%(Esc)")
            $isAspenOpen = Get-Process Aspen*
            }
        }
        #Aspen has been closed run code here:
    }
1
Miguel García On

Thanks Psychon Solutions! It works!! I used it from python like follows:

import win32com.client as win32

shell = win32.Dispatch("WScript.Shell")
shell.AppActivate("All licenses are in use")
shell.Sendkeys("%{F4}", 0)

Now I only have to improve the code to automate the task.