When the script below is active, some functionality is added when an OpenStudio window has focus.
The following shortcuts are available, and work on the most recently run .osm-file (based on modified date):
- Ctrl+R: Opens Resultsviewer (and goes
to tree view + collapses the tree)
- Ctrl+E: Opens the .err in Notepad++
- Ctrl+D: Opens the folder in explorer
- Ctrl+Q: Closes Resultsviewer (so that no file conflict occurs when running simulation)
I didn't do any thorough testing, so it may need modifications on your system. Feel free to use/modify.
SetTitleMatchMode, 2
; OpenStudio Shortcuts
OSDir()
{
NewestTime = 20100101000000
NewestName = 0
Loop, %USERPROFILE%\AppData\Local\Temp\OpenStudio*,2
{
;dt = %A_LoopFileTimeModified%
FileGetTime, dt, %A_LoopFileFullPath%\resources
EnvSub, dt, %NewestTime%, seconds
if dt > 0 ; Source file is newer than destination file.
{
IfExist, %A_LoopFileFullPath%\resources\run ; Folder contains run data
{
;NewestTime = %A_LoopFileTimeModified%
FileGetTime, NewestTime, %A_LoopFileFullPath%\resources
NewestName = %A_LoopFileFullPath%
}
}
}
;Newest folder is %NewestName%
return %NewestName%
}
#IfWinActive, osm ahk_class Qt5QWindowIcon
; Open most recent SQL database in ResultsViewer
^r::
OSD := OSDir()
Run "C:\Program Files\OpenStudio 1.6.0\bin\ResultsViewer.exe" "%OSD%\resources\run\5-EnergyPlus-0\eplusout.sql"
WinWait, ResultsViewer,
IfWinNotActive, ResultsViewer, , WinActivate, ResultsViewer,
WinWaitActive, ResultsViewer,
;MouseClick, left, 136, 182
ControlClick, x136 y182
Sleep, 100
;MouseClick, left, 152, 208
ControlClick, x152 y208
Sleep, 100
Send, {DOWN}{LEFT}{DOWN}{LEFT}{DOWN}{LEFT}{DOWN}{LEFT}{DOWN}{LEFT}{DOWN}{LEFT}{DOWN}{LEFT}{DOWN}{LEFT}{DOWN}{LEFT}{DOWN}{LEFT}{DOWN}{LEFT}
Return
; Open E+ Error file with Notepad++
^e::
OSD := OSDir()
Run "C:\Program Files (x86)\Notepad++\notepad++.exe" "%OSD%\resources\run\5-EnergyPlus-0\eplusout.err"
Return
; Open Directory containing files
^d::
OSD := OSDir()
Run explorer.exe "%OSD%\resources\run"
Return
; Close ResultsViewer so no file conflict occurs when running simulation in OpenStudio
^q::
WinClose ResultsViewer ahk_class Qt5QWindowIcon
Return
#IfWinActive
This is great, thanks for sharing. But can you please phrase it as a question ("How can you automate opening results viewer to see the latest .err file?) and put your solution as an answer?
Sure! I realized this wasn't a question, but wanted to share in case someone should find it helpful
Answering your own question is perfectly fine and even recommended! Thanks for adjusting.