Last active
February 17, 2025 11:13
-
-
Save yamadaaaaaaa/58879fcebeb830f31a1262362ef177a5 to your computer and use it in GitHub Desktop.
py_ae.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # python3.7.7 pyside2 | |
| import sys | |
| import os | |
| import win32gui | |
| import win32api | |
| import win32con | |
| from PySide2 import QtCore, QtGui, QtWidgets | |
| # 起動中のツールUIを探す | |
| def search_this_winEnumHandler( _hwnd, list_window ): | |
| if win32gui.IsWindowVisible( _hwnd ): | |
| if 0 < win32gui.GetWindowText( _hwnd ).rfind('test'): | |
| list_window.append((_hwnd, win32gui.GetWindowText(_hwnd))) | |
| # 起動中のAEを探す | |
| def search_ae_winEnumHandler( _hwnd, list_window ): | |
| if win32gui.IsWindowVisible( _hwnd ): | |
| if 0 < win32gui.GetWindowText( _hwnd ).rfind('.aep'): | |
| list_window.append((_hwnd, win32gui.GetWindowText(_hwnd))) | |
| # ボタン押下時にAEにコマンド送信する | |
| def test(mainWindow): | |
| # 起動中のAEを探す | |
| list_window = list() | |
| win32gui.EnumWindows( search_ae_winEnumHandler, list_window ) | |
| if not list_window:return | |
| ae_window_title = list_window[0][1] | |
| ae_window = win32gui.FindWindow(None, ae_window_title) | |
| # jsx処理によってはalert出すときなどツールUIが邪魔なので最小化 tool window min | |
| mainWindow.setWindowState(QtCore.Qt.WindowMinimized) | |
| # AEのウィンドウサイズ状態取得 get ae window size | |
| window_state = win32gui.GetWindowPlacement(ae_window) | |
| #win32gui.EnableWindow(ae_window,False) | |
| # jsxの実行 | |
| subprocess.call('AfterFX.exe -ro test.jsx') | |
| # ツールUI戻す Undo tool windowsize | |
| mainWindow.setWindowState(QtCore.Qt.WindowActive) | |
| #win32gui.EnableWindow(ae_window,True) | |
| # jsxを実行するとAEPをダブルクリックで開いた時のようにAEのウィンドウサイズが変わるため元に戻す Undo AE window size | |
| if window_state[1] == win32con.SW_SHOWMAXIMIZED: | |
| win32gui.ShowWindow(ae_window, win32con.SW_MAXIMIZE) | |
| elif window_state[1] == win32con.SW_SHOWMINIMIZED: | |
| win32gui.ShowWindow(ae_window, win32con.SW_SHOWMINIMIZED) | |
| elif window_state[1] == win32con.SW_SHOWNORMAL: | |
| win32gui.ShowWindow(ae_window, win32con.SW_SHOWNORMAL) | |
| # tool window | |
| class set_mainWindow(QtWidgets.QWidget): | |
| def __init__(self): | |
| super().__init__() | |
| self.button = QtWidgets.QPushButton("call jsx", self) | |
| self.button.clicked.connect(lambda: test(self)) | |
| self.setWindowTitle('test') | |
| def main(): | |
| app = QtWidgets.QApplication(sys.argv) | |
| mainWindow = set_mainWindow() | |
| # 既存のUI起動があれば削除 deleteUI | |
| list_window = list() | |
| list_cmdWindow = list() | |
| win32gui.EnumWindows( search_this_winEnumHandler, list_window ) | |
| for _win in list_window: | |
| if os.sep in _win[1]:continue | |
| list_cmdWindow.append(_win[0]) | |
| if len(list_cmdWindow) > 1: | |
| win32gui.PostMessage(list_cmdWindow[1],win32con.WM_CLOSE,0,0) | |
| # --- | |
| # 操作性や、AEとの連動感出すため常に手前に表示 | |
| mainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) | |
| mainWindow.show() | |
| mainWindow.setAttribute(QtCore.Qt.WA_DeleteOnClose) | |
| sys.exit(app.exec_()) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment