qmasingarbe / pymiere

Python for Premiere pro
GNU General Public License v3.0
353 stars 46 forks source link

Getting Tick count from a sequence only comes back incorrectly #58

Closed JonD0t closed 1 year ago

JonD0t commented 1 year ago

For some reason when i run this it will say that the Tempseq is 3 mins long, when the clip i am importing is 11 seconds long. The tick count is correct only when i recreate an error (See below) after the code that is supposed to grab the tick count.

Error: Traceback (most recent call last): File "c:\twitchclipadobe\twitchcliptoreel.py", line 97, in tempSeqEndSeconds = tempSeqEndticks.seconds AttributeError: 'int' object has no attribute 'seconds'

import pymiere as pym
import time

# gets input for the File Path of the Raw Twitch Clip.
# currently only set up for the cam on the right side.
rawClip = input("Enter File Path")
rawClipPath = rawClip.replace('"', "")
print(rawClipPath)

# opens the project file. Premiere must already be open.
pym.objects.app.openDocument("D:\JonDotYT\Reel template.prproj")

# Counts number of project items in the project folder
numofItems = pym.objects.app.project.rootItem.children.numItems
print("")
print("Number of Project Items: ")
print(numofItems)
print("")

# takes items in the project list as an list
itemList = pym.objects.app.project.rootItem.children

# enumerates (splits the list up) for each item in the list
iLenumerated = enumerate(itemList)
for i in iLenumerated:
    print("pymiere ID of Items ")
    print(i)
    print("Item Name: " + itemList[i[0]].name)
    print("")

# safety check to make sure that the offline clip that is to be replaced is found and selected
i = 0
clipToReplacestr = pym.objects.app.project.rootItem.children[0].name
while clipToReplacestr != "1. REPLACE WITH RAW CLIP":
    clipToReplacestr = pym.objects.app.project.rootItem.children[i].name
    clipToReplace = pym.objects.app.project.rootItem.children[i]
    i += 1
    if i > numofItems:
        print("No item found with name: 1. REPLACE WITH RAW CLIP. Please ensure you have the correct file.")
        quit()

# prints status check
print("found " + clipToReplacestr)
print("")
print("Pymiere project item ID:")
print(clipToReplace)

# replaces Offline video placeholder with selected video footage.
clipToReplace.changeMediaPath(rawClipPath, False)

# Creates a Sequence from the replaced clip to get the start and end time codes
tempSequence = pym.objects.app.project.createNewSequenceFromClips(
    "Tempseq", clipToReplace, None)

# Counts number of project items in the project folder
numofItems = pym.objects.app.project.rootItem.children.numItems
print("")
print("Number of Project Items: ")
print(numofItems)
print("")

itemList = pym.objects.app.project.rootItem.children
# enumerates (splits the list up) for each item in the list
iLenumerated = enumerate(itemList)
for i in iLenumerated:
    print("pymiere ID of Items ")
    print(i)
    print("Item Name: " + itemList[i[0]].name)
    print("")

# safety check to make sure that the Sequencec that is to be measured is found and selected
i = 0
tempSeqVar = pym.objects.app.project.rootItem.children[0].name
while tempSeqVar != "Tempseq":
    tempSeqVar = pym.objects.app.project.rootItem.children[i].name
    tempSeqindex = i
    i += 1
if i > numofItems:
    print("No item found with name: Tempseq. Please ensure you have the correct file.")
    quit()

#added wait for debugging the ticks issue, didn't resolve
#time.sleep(5)

print("Tempseq index:")
print(tempSeqindex)
print("")
tempSeqEndticks = pym.objects.app.project.sequences[tempSeqindex].end

print("Tempseq in Ticks:")
print(tempSeqEndticks)
print("")
tickPS = 254016000000

# ISSUE IS WHEN TRACEBACK ERROR WITH .seconds IS IN TICK VALUE COMES BACK CORRECTLY. WHEN IT THE MATH IS CORRECT THE VALUE
# FOR TICKS OF TEMPSEQ COMES BACK AS 3 MINUTES INSTEAD OF 11 SECONDS
#UNCOMMENTING BELOW WILL SHOW CORRECT VALUE FOR temSeqEndticks
#tempSeqEndSeconds = tempSeqEndticks.seconds
print("Tempseq in Seconds:")
# print(tempSeqEndSeconds)
JonD0t commented 1 year ago

Premiere version: 23.0 Python: 3.10.8

JonD0t commented 1 year ago

After much testing and amateur level coding, Premiere seems to change the order in which it holds the sequences. so I created a means to find the index values for each time the project is opened.

##############################################################################
#GETTING SEQUENCE IDS, IDEX, AND NAME STRING
##############################################################################

#sets list of sequences in project
seqList = pym.objects.app.project.sequences

#enumerates list
i = 0
sLenumerated = enumerate(seqList)
for i in sLenumerated:
    print("pymiere ID of sequences ")
    print(i)
    print("Sequence Name: " + seqList[i[0]].name)
    print("")

#loops through sequences looking for Tempseq
i = 0
tempSeqNamestr = pym.objects.app.project.sequences[0].name
renderSeqName = pym.objects.app.project.sequences[0].name
print(tempSeqNamestr)
tempSeqID = pym.objects.app.project.sequences[0]
print("")
while tempSeqNamestr != "Tempseq":
    tempSeqNamestr = pym.objects.app.project.sequences[i].name
    tempSeqID = pym.objects.app.project.sequences[i]
    tempSeqIndex = i
    i += 1
    if i > numOfSequences:
        print("No sequence found with name: Tempseq. Please ensure you have the correct proj file.")
        quit()

#cements variables 
tempSeqIndex = tempSeqIndex
tempSeqID = tempSeqID
tempSeqNamestr = tempSeqNamestr

#loops through sequences looking for render sequence
i = 0
while renderSeqName != "2. TRIM LENGTH CAPTION AND EXPORT":
    renderSeqName = pym.objects.app.project.sequences[i].name
    renderSeqIndex = i
    renderSeqID = pym.objects.app.project.sequences[i]
    i += 1
    if i > numOfSequences:
        print("No sequence found with name: Tempseq. Please ensure you have the correct proj file.")
        quit()

renderSeqID = renderSeqID
renderSeqIndex = renderSeqIndex
renderSeqName = renderSeqName
##################################################################################
hedley-david commented 1 year ago

Hello,

Here is how I find sequences in PPro, with a function to create dictionaries.


proj = pymiere.objects.app.project
ALL_SEQ = {}

#this is a function to create a dictionary of all sequences in the project.
def sequences_to_dict():
    for s in range(0, proj.sequences.__len__()):
        ALL_SEQ[proj.sequences[s].name] = proj.sequences[s].sequenceID
    return ALL_SEQ

#runs the function
sequences_to_dict()

#this will give you the sequenceID of all your sequences
print(ALL_SEQ)

#you can specify the seq you're looking for like this
print(ALL_SEQ['Temp Seq'])

#this is how you can render something based on the name in the bin
renderSeqName = (ALL_SEQ['Temp Seq']) 

then I can call sequences by name no matter where they are.