Skip to main content
aaraot
Participant
April 7, 2026
Question

I'm trying to create cuts automatically using UXP but I can't stack them up, like create multiple cuts from source media and add them to the sequence, in a way that they are created at the end of the last cut

  • April 7, 2026
  • 0 replies
  • 19 views
Hi everyone,I'm building a UXP plugin for Premiere Pro that takes a list of cuts (start/end times) identified by AI and adds them to a sequence. My goal is to "stack" these clips so each new cut starts exactly where the previous one ends.The Problem: I've tried several methods from the UXP API, but I'm struggling to get the clips to move to the correct position.
async function importTag(tags) {
console.log("Import Tag:", tags);
try {
const project = await app.Project.getActiveProject();

if (project) {
const sequence = await project.getActiveSequence();
const sequenceEditor = await app.SequenceEditor.getEditor(sequence);

const rootItem = await project.getRootItem();
const items = await rootItem.getItems();

const sequenceMarkers = await app.Markers.getMarkers(sequence);

for (const tag of tags) {
if (tag.markers) {
tag.InTc = tag.markers[0];
tag.OutTc = tag.markers[1];
}
await trim(project, sequence, sequenceEditor, sequenceMarkers, items, tag);
}
}
} catch (error) {
console.error("Error UXP:", error);
}
}

async function trim(project, sequence, sequenceEditor, sequenceMarkers, items, tag) {
try {
const inPoint = await app.TickTime.createWithSeconds(timecodeToSeconds(tag.InTc));
const outPoint = await app.TickTime.createWithSeconds(timecodeToSeconds(tag.OutTc));

project.lockedAccess(() => {
project.executeTransaction((compoundAction) => {
const action = sequenceEditor.createInsertProjectItemAction(
items[0],
inPoint,
0,
0,
true
);

compoundAction.addAction(action);

console.log("TrackItem Inserted");
}, "TrackItem Inserted");
});

const videoTrack = await sequence.getVideoTrack(0);
const videoTrackItems = await videoTrack.getTrackItems(app.Constants.TrackItemType.CLIP, false);
const newVideoTrackItem = videoTrackItems.find(item => !('id' in item));
if (newVideoTrackItem) {
newVideoTrackItem.id = tag['$id'];
}

const audioTrackCount = await sequence.getAudioTrackCount();
const audios = [];
for (let i = 0; i < audioTrackCount; i++) {
const audioTrack = await sequence.getAudioTrack(i);
const audioTrackItems = await audioTrack.getTrackItems(app.Constants.TrackItemType.CLIP, false);
const newAudioTrackItem = audioTrackItems.find(item => !('id' in item));
if (newAudioTrackItem) {
newAudioTrackItem.id = tag['$id'];
audios.push(newAudioTrackItem);
}
}

project.lockedAccess(() => {
project.executeTransaction((compoundAction) => {
audios.map(audio => {
const trimInAction = audio.createSetInPointAction(inPoint);
const trimOutAction = audio.createSetOutPointAction(outPoint);
compoundAction.addAction(trimInAction);
compoundAction.addAction(trimOutAction);

const setStartAction = audio.createSetStartAction(inPoint);
compoundAction.addAction(setStartAction);
});

const setStartAction = newVideoTrackItem.createSetStartAction(inPoint);
compoundAction.addAction(setStartAction);

const trimInAction = newVideoTrackItem.createSetInPointAction(inPoint);
const trimOutAction = newVideoTrackItem.createSetOutPointAction(outPoint);
compoundAction.addAction(trimInAction);
compoundAction.addAction(trimOutAction);

const addMarkerAction = sequenceMarkers.createAddMarkerAction(
`${tag.TagType} Marker`,
app.Marker.MARKER_TYPE_COMMENT,
app.TickTime.createWithSeconds(timecodeToSeconds(tag.InTc)),
app.TickTime.createWithSeconds(timecodeToSeconds(tag.OutTc)),
tag.Notes ? tag.Notes : 'N/A'
);
compoundAction.addAction(addMarkerAction);

console.log("TrackItem Trimmed + Marker Inserted");
}, "TrackItem Trimmed + Marker Inserted");
});
} catch (error) {
console.error("Error UXP:", error);
}
}
Thanks!