First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
I've used printdiagfile() to batch print pdfs. I think it is sensitive to the printer you are using to print to pdf (eg. Adobe, Microsoft, etc). Some pdf software has settings for location, automatic file naming, and options to append to existing files. I think Adobe defaults the filename to the same as the SLD filename and you need to print one SLD manually to set where to save the files.
I used "win32gui" python module to find the "Save PDF File As" window and use "SendKeys" python module to send the inputs automatically with python.
2 | No.2 Revision |
I've used printdiagfile() to batch print pdfs. I think it is sensitive to the printer you are using to print to pdf (eg. Adobe, Microsoft, etc). Some pdf software has settings for location, automatic file naming, and options to append to existing files. I think Adobe defaults the filename to the same as the SLD filename and you need to print one SLD manually to set where to save the files.
I used "win32gui" python module to find the "Save PDF File As" window and use "SendKeys" python module to send the inputs automatically with python.
edit: It's 2 separate scripts, 1 script ran from the PSSE GUI to handle all of the opening, modification, saving, and printing of the PSSE SLDs. The other script run concurrently (not in psse tho) to detect and interact with the pop-up windows. An alternate to the second script is to just hold the enter key down. This is sensitive to the printer.
import os
import psspy
def exportAsPDF():
os.system("TASKKILL /F /IM acrobat.exe")
psspy.refreshdiagfile()
psspy.printdiagfile(r"""Adobe PDF""",1,1) # (Name of printer, # of copies, 1=Portrait/2=landscape)
os.system("TASKKILL /F /IM acrobat.exe")
import win32gui
import re
import SendKeys
class WindowFinder:
# """Class to find and make focus on a particular Native OS dialog/Window """
def __init__ (self):
self._handle = None
def find_window(self, class_name, window_name = None):
# """Pass a window class name & window name directly if known to get the window """
self._handle = win32gui.FindWindow(class_name, window_name)
def _window_enum_callback(self, hwnd, wildcard):
# '''Call back func which checks each open window and matches the name of window using reg ex'''
if re.match(wildcard, str(win32gui.GetWindowText(hwnd))) != None:
self._handle = hwnd
def find_window_wildcard(self, wildcard):
# """ This function takes a string as input and calls EnumWindows to enumerate through all open windows """
self._handle = None
win32gui.EnumWindows(self._window_enum_callback, wildcard)
def set_foreground(self):
# """Get the focus on the desired open window"""
win32gui.SetForegroundWindow(self._handle)
win = WindowFinder()
while True:
try:
win.find_window_wildcard(".*Save PDF File As.*")
win.set_foreground()
SendKeys.SendKeys("{ENTER}") #Use SendKeys to send ENTER key stroke to Save As dialog
win.find_window_wildcard(".*Confirm Save As.*")
win.set_foreground()
SendKeys.SendKeys("{Y}") #Use SendKeys to send Y key stroke to Save As dialog
except:
pass