Script to relink Graphics

Do you have questions about Desktop Video, Converters, Routers and Monitoring?
  • Author
  • Message
Offline
User avatar

Krejue

  • Posts: 8
  • Joined: Wed Feb 08, 2023 10:37 am
  • Real Name: Jürg Krebs

Script to relink Graphics

PostThu Mar 28, 2024 2:27 pm

We have some graphics, who do relink wrong. Its seems, Resolve does not check the filename or is confused about something. Most of our lower graphics do work, but some are completely wrong. That is very bad, because the original name disappears when linked to the wrong media. With a script we would like to reconnect the graphics by their name and length. There seems to be no way to link to clips to the timeline item. Any good ideas about our workaround?


function findMatchingClipInMediaPool(name, duration)
local project = resolve:GetProjectManager():GetCurrentProject()
local mediaPool = project:GetMediaPool()
local rootFolder = mediaPool:GetRootFolder()

local function scanFolder(folder)
local clips = folder:GetClips()
for _, clip in pairs(clips) do
local clipProps = clip:GetClipProperty()
if clipProps["Clip Name"] == name and tonumber(clipProps["Frames"]) == duration then
return clip
end
end

local subFolders = folder:GetSubFolders()
for _, subFolder in pairs(subFolders) do
local matchingClip = scanFolder(subFolder)
if matchingClip then
return matchingClip
end
end
end

return scanFolder(rootFolder)
end

function relinkOfflineClips()
print("Starting to relink offline clips...")
local project = resolve:GetProjectManager():GetCurrentProject()
local timeline = project:GetCurrentTimeline()
if not timeline then
print("No timeline selected.")
return
end

local videoTrackIndex = 1 -- Example: using the first video track
local trackItems = timeline:GetItemListInTrack("video", videoTrackIndex)
if trackItems then
for _, item in ipairs(trackItems) do
local mediaPoolItem = item:GetMediaPoolItem()
if mediaPoolItem then -- Check if the timeline item is linked to a media pool item
local clipProps = mediaPoolItem:GetClipProperty()
if clipProps then
local offlineStatus = clipProps["Offline"]
local name = clipProps["Clip Name"]
local duration = tonumber(clipProps["Frames"])
if offlineStatus then
print("Attempting to relink: " .. name)
local matchingClip = findMatchingClipInMediaPool(name, duration)
if matchingClip then
-- Attempt to replace the media pool item of the timeline item with the matching one
if item:ReplaceMediaPoolItem(matchingClip) then
print("Successfully relinked offline clip: " .. name)
else
print("Failed to relink clip: " .. name)
end
else
print("No matching clip found for: " .. name)
end
end
end
else
print("Item does not have an associated media pool item or is offline.")
end
end
else
print("No items found in the specified track.")
end
print("Finished attempting to relink clips.")
end

relinkOfflineClips()

Return to Post Production

Who is online

Users browsing this forum: No registered users and 45 guests