- Posts: 6
- Joined: Mon Apr 25, 2022 6:05 am
- Real Name: Jan-Hendrik Müller
Hi there!
I'm new to the scripting API, and I was wondering:
Is there a way I can shift the first clip in the timeline one second to the right?
I was able to write the below script, which takes the first clip in the timeline and scales it down to 0.8 by `first_clip.SetProperty("ZoomX", 0.8)` and that works fine.
However, shifting the clip to the right does not work.
The function first_clip.GetStart() gets the start time correctly.
However, there is no function first_clip.SetStart()
Furthermore, I've tried`first_clip.SetProperty("Start", new_start)` but that also did not work.
any other ideas? Would be really great if there was a possibility to move clips via the API
```py
import sys
sys.path.append('/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules')
import DaVinciResolveScript as dvr_script
# Initialize DaVinci Resolve scripting interface
resolve = dvr_script.scriptapp("Resolve")
# Get project manager and the current project
projectManager = resolve.GetProjectManager()
currentProject = projectManager.GetCurrentProject()
# Get the current timeline from the current project
currentTimeline = currentProject.GetCurrentTimeline()
# Get the number of video tracks in the timeline
video_track_count = currentTimeline.GetTrackCount("video")
# Retrieve the first clip in the first video track
if video_track_count > 0:
video_clips = currentTimeline.GetItemListInTrack("video", 1)
if video_clips:
first_clip = video_clips[0]
# Scale the clip by setting ZoomX and ZoomY to 0.8
first_clip.SetProperty("ZoomX", 0.8) # this works
first_clip.SetProperty("ZoomY", 0.8) # this works
# Get the original start time of the clip
original_start = first_clip.GetStart()
# Calculate the new start time by shifting one second to the right
timeline_frame_rate = float(currentTimeline.GetSetting("timelineFrameRate"))
frames_to_shift = int(timeline_frame_rate) # Number of frames in one second
new_start = original_start + frames_to_shift
# Set the new start time for the clip using SetProperty
result = first_clip.SetProperty("Start", new_start)
print(f"Original start time: {original_start}")
print(f"New start time: {new_start}")
print(f"SetProperty result: {result}")
# Verify that the properties have been updated
properties = first_clip.GetProperty()
for key, value in properties.items():
print(f"{key}: {value}")
else:
print("No clips found in the first video track.")
else:
print("No video tracks found in the timeline.")
```
out:
```
Original start time: 216000
New start time: 216060
SetProperty result: False
Pan: 0.0
Tilt: 0.0
ZoomX: 0.8
ZoomY: 0.8
ZoomGang: True
RotationAngle: 0.0
AnchorPointX: 0.0
AnchorPointY: 0.0
Pitch: 0.0
Yaw: 0.0
FlipX: False
FlipY: False
CropLeft: 0.0
CropRight: 0.0
CropTop: 0.0
CropBottom: 0.0
CropSoftness: 0.0
CropRetain: False
DynamicZoomEase: 0
CompositeMode: 0
Opacity: 100.0
Distortion: 0.0
RetimeProcess: 0
MotionEstimation: 0
Scaling: 0
ResizeFilter: 0
```
I'm new to the scripting API, and I was wondering:
Is there a way I can shift the first clip in the timeline one second to the right?
I was able to write the below script, which takes the first clip in the timeline and scales it down to 0.8 by `first_clip.SetProperty("ZoomX", 0.8)` and that works fine.
However, shifting the clip to the right does not work.
The function first_clip.GetStart() gets the start time correctly.
However, there is no function first_clip.SetStart()
Furthermore, I've tried`first_clip.SetProperty("Start", new_start)` but that also did not work.
any other ideas? Would be really great if there was a possibility to move clips via the API
```py
import sys
sys.path.append('/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules')
import DaVinciResolveScript as dvr_script
# Initialize DaVinci Resolve scripting interface
resolve = dvr_script.scriptapp("Resolve")
# Get project manager and the current project
projectManager = resolve.GetProjectManager()
currentProject = projectManager.GetCurrentProject()
# Get the current timeline from the current project
currentTimeline = currentProject.GetCurrentTimeline()
# Get the number of video tracks in the timeline
video_track_count = currentTimeline.GetTrackCount("video")
# Retrieve the first clip in the first video track
if video_track_count > 0:
video_clips = currentTimeline.GetItemListInTrack("video", 1)
if video_clips:
first_clip = video_clips[0]
# Scale the clip by setting ZoomX and ZoomY to 0.8
first_clip.SetProperty("ZoomX", 0.8) # this works
first_clip.SetProperty("ZoomY", 0.8) # this works
# Get the original start time of the clip
original_start = first_clip.GetStart()
# Calculate the new start time by shifting one second to the right
timeline_frame_rate = float(currentTimeline.GetSetting("timelineFrameRate"))
frames_to_shift = int(timeline_frame_rate) # Number of frames in one second
new_start = original_start + frames_to_shift
# Set the new start time for the clip using SetProperty
result = first_clip.SetProperty("Start", new_start)
print(f"Original start time: {original_start}")
print(f"New start time: {new_start}")
print(f"SetProperty result: {result}")
# Verify that the properties have been updated
properties = first_clip.GetProperty()
for key, value in properties.items():
print(f"{key}: {value}")
else:
print("No clips found in the first video track.")
else:
print("No video tracks found in the timeline.")
```
out:
```
Original start time: 216000
New start time: 216060
SetProperty result: False
Pan: 0.0
Tilt: 0.0
ZoomX: 0.8
ZoomY: 0.8
ZoomGang: True
RotationAngle: 0.0
AnchorPointX: 0.0
AnchorPointY: 0.0
Pitch: 0.0
Yaw: 0.0
FlipX: False
FlipY: False
CropLeft: 0.0
CropRight: 0.0
CropTop: 0.0
CropBottom: 0.0
CropSoftness: 0.0
CropRetain: False
DynamicZoomEase: 0
CompositeMode: 0
Opacity: 100.0
Distortion: 0.0
RetimeProcess: 0
MotionEstimation: 0
Scaling: 0
ResizeFilter: 0
```