If the script always prints "LockedStatus was initialized to Unlocked (0)," it indicates that the script isn't identifying the existing marker correctly, leading to the creation of a new marker each time. This issue could stem from how the marker is being detected or accessed. Let's adjust the logic to ensure the marker is correctly identified, accessed, and toggled within the timeline.
Here’s how you can revise the script:
- Ensure markers are being retrieved correctly.
- Handle unique marker identification and toggling robustly.
Here's the revised script:
-- Function to retrieve project manager and current project
local function getProject()
local projectManager = resolve:GetProjectManager()
return projectManager:GetCurrentProject()
end
-- Function to get the current timeline
local function getTimeline(project)
if project then
return project:GetCurrentTimeline()
end
end
-- Function to find the status marker on the timeline
local function findStatusMarker(timeline)
local markers = timeline:GetMarkers()
for frameId, marker in pairs(markers) do
if marker.name == "LockedStatusMarker" then
return frameId, marker
end
end
return nil, nil
end
-- Function to toggle the marker note status
local function toggleStatusMarker(note)
if note == "1" then
return "0" -- Toggle to unlocked
else
return "1"
end
end
-- Function to create the marker if it doesn't exist
local function createStatusMarker(timeline, status)
timeline:AddMarker(1, "Green", "LockedStatusMarker", status)
end
-- Main Execution
local project = getProject()
local timeline = getTimeline(project)
if timeline then
local frameId, marker = findStatusMarker(timeline)
if marker then
-- Toggle the status and update the marker
local newStatus = toggleStatusMarker(marker.note)
timeline:DeleteMarkerAtFrame(frameId)
timeline:AddMarker(frameId, "Green", "LockedStatusMarker", newStatus)
print("LockedStatus is now:", newStatus == "1" and "Locked" or "Unlocked")
else
-- Create an initial marker with "0" (unlocked) state if none exists
createStatusMarker(timeline, "0")
print("LockedStatus was initialized to Unlocked (0).")
end
else
print("No timeline open.")
end
Key Adjustments:
- Marker Retrieval: The script ensures it correctly iterates over all markers using the
pairs function, handling any discrepancies in marker assignments.
- Frame Identification: When finding the status marker, both
frameId and marker are returned, allowing us to accurately identify and operate on the correct marker.
- Robustness: By targeting the frame ID more carefully, the script now upholds the intended operation, toggling the marker note accordingly.
This revised version should correctly toggle the LockedStatus on each run, assuming the timeline is active and correctly loaded. Assign this script to your hotkey setup for quick toggling as desired.