def create_prproj_from_template(project): """ Launches Premiere Pro if not already running; Prompts to open a template .prpoj file; Saves the .prproj file with a path based on .title and .dirpath """ # Start Premiere Pro and open the selected project if not exe_utils.exe_is_running("adobe premiere pro.exe")[0]: exe_utils.start_premiere() create_global_shortcuts() if project.prproj_path.is_file(): app.openDocument(str(project.prproj_path)) else: app.openDocument(str(project.template_path)) app.project.saveAs(str(project.prproj_path))
def check_premiere_is_alive(crash=True): """ Check if premiere is running and if the pymiere CEP panel is active :param crash: (bool) what to do if premiere is not connected :return: (bool) is premiere ready to receive instruction from python """ # search in globals the last time premiere was checked and if we need to chack again global last_alive_check_time if "last_alive_check_time" in globals( ) and current_time() - last_alive_check_time < ALIVE_TIMEOUT: return True # is premiere pro launched running, pid = exe_is_running("adobe premiere pro.exe") if not running: msg = "Premiere Pro is not running" if crash: raise ValueError(msg) print(msg) return False # is the CEP panel reachable try: response = requests.get(PANEL_URL) except requests.exceptions.ConnectionError: msg = "No connection could be established to Premiere Pro, check that the pymiere pannel is loaded" if crash: raise IOError(msg) print(msg) return False if response.content.decode("utf-8") != "Premiere is alive": msg = "Found running server on '{}' but got wrong response for ping".format( PANEL_URL) if crash: raise ValueError() print(msg) return False last_alive_check_time = current_time() return True
import pymiere import pymiere.exe_utils as pymiere_exe import requests # start premiere if pymiere_exe.exe_is_running("adobe premiere pro.exe")[0]: raise ValueError("There already is a running instance of premiere") pymiere_exe.start_premiere() # open a project pymiere.objects.app.openDocument( "C:\\Users\\Quentin\\Desktop\\temp\\test.pproj") # set sequence named hello world as active sequence sequences = pymiere.objects.app.project.sequences sequence = next(filter(lambda s: s.name == "hello world", sequences)) pymiere.objects.app.project.openSequence(sequence.sequenceID) pymiere.objects.app.project.activeSequence = sequence # rename sequence and query info pymiere.objects.app.project.activeSequence.name = "renamed sequence" print(pymiere.objects.app.project.activeSequence.getPlayerPosition().seconds) pymiere.objects.app.project.activeSequence.name = "hello world" # rename back for test to work next time pymiere.objects.app.project.save() # close premiere try: pymiere.objects.app.quit() except requests.exceptions.ConnectionError: print("Success") pass
import pymiere # import pymiere.exe_utils as pymiere_exe from pymiere import exe_utils # Less confusing I think import requests import PySimpleGUI as sg from pathlib import Path # Use PySimpleGui to select a .pproj file path = Path( sg.popup_get_file( "Please select a Premiere Pro project to open", default_path="C:\\Users\\Quentin\\Desktop\\temp\\test.pproj", file_types=(("Premiere Pro", "*.prproj"), ))) # Start Premiere Pro and open the selected project if not exe_utils.exe_is_running("adobe premiere pro.exe")[0]: exe_utils.start_premiere() # TODO: Perhaps rename to just 'exe_utils.start'? Mentioning premiere seems unnecessary... app = pymiere.objects.app app.openDocument(str(path)) # TODO: It would be nice for .openDocument to take a pathlib object itself (so you don't have to remember str(path). # TODO: It would also be nice to be able to start Premiere and open a Project all in one command by passing a Path argument e.g. exe_utils.start(path) # Open "hello world" and set it as the active sequence; if "hello world" doesn't exist, use the first Sequence found. sequences = app.project.sequences # TODO: Can we remove wrappers.list_sequences() from demo.py? This seems easier and more readable! name = "hello world" sequence = list([s for s in sequences if s.name == name] or sequences)[0] app.project.openSequence(sequence.sequenceID) app.project.activeSequence = sequence # If there's any chance you might be changing the active sequence again, you can keep using 'app.project.activeSequence' to periodically check the CURRENT active sequence, otherwise the object stored as 'sequence' should do just fine.