Setting the in and out points of a clip using an extension, and other related questions.
Hello,
I'm a beginner in developing extensions for Premiere Pro, and I have a few questions while writing .jsx scripts:
Is there a way to create an undo group in Premiere Pro extensions, similar to After Effects scripts?
For example, like this in AE:
app.beginUndoGroup("tttest"); app.endUndoGroup();
Is it possible to modify the text content created using the Text Tool (Essential Graphics) via the extension?
I tried to set the in and out points of a graphic clip in the sequence to a specific range — for example, from frame 24 to frame 48.
However, setting .clip.start doesn't seem to work correctly. Could you provide a working code example for how to reposition and trim a graphic clip in the timeline?
Here is a portion of the .jsx code related to my third question.
function but3onClick() {
var sequence = app.project.activeSequence;
if (!sequence) { app.setSDKEventMessage("没有活动序列", "warning"); return; }
var selectedClips = getSelectedClips(); // 获取选中的剪辑
if (!selectedClips) return;
if (selectedClips.length > 1) { app.setSDKEventMessage("请只选择单个剪辑", "warning"); return; }
var selectedClip = selectedClips[0].clip; // 获取选中的剪辑对象
var track = sequence.videoTracks[selectedClips[0].trackIndex]; // 获取选中剪辑所在的轨道
var ticksPerFrame = sequence.timebase; // 获取时间基准(每帧的ticks数)
for (var i = track.clips.length - 1; i >= 0; i--) { // 遍历轨道上的所有剪辑
var clip = track.clips[i];
if (clip.start.ticks == selectedClip.start.ticks && clip.end.ticks == selectedClip.end.ticks)
continue;
track.clips[i].remove(0, 0);
}
selectedClip.start = new Time();
selectedClip.start.ticks = 24 * ticksPerFrame;
}
//获取选中的剪辑
function getSelectedClips() {
var sequence = app.project.activeSequence;
if (!sequence) { return; }
var selectedClips = [];
for (var i = 0; i < sequence.videoTracks.length; i++) {
var track = sequence.videoTracks[i];
for (var j = 0; j < track.clips.length; j++) {
var clip = track.clips[j];
if (clip.isSelected())
selectedClips.push({
clip: clip,
trackIndex: i,
});
}
}
if (!selectedClips || selectedClips.length == 0) { // 如果没有选中剪辑
app.setSDKEventMessage("当前没有选中任何剪辑", "warning"); return;
}
var baseTrackIndex = selectedClips[0].trackIndex; // 获取第一个选中剪辑的轨道索引
for (var i = 1; i < selectedClips.length; i++)
if (selectedClips[i].trackIndex != baseTrackIndex) {
app.setSDKEventMessage("选中的剪辑不在同一轨道上", "warning");
return;
}
return selectedClips;
}
