2

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 Answers2

2

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:
    }
PandaSurge
  • 370
  • 1
  • 7
  • 18
2

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.

  • if you would like to automate this task you could create a cronjob equivalent for windows called a scheduled task. You'll be able to select the date, time etc.. that you would like the scheduled task to execute. Im assuming this is the kind of automation you're after? – PandaSurge Apr 25 '19 at 15:48
  • 1
    Yes, it is. I did a simple script who checks if the window is open every 30sec and if that's so, close it. It's working well! Now I can keep running my simulations and sleep well :D – Miguel García Apr 26 '19 at 07:27