UXP for Premiere - How To Marker Change Color
I have another question while migrating marker logic from CEP to UXP.
In CEP, the previous code looked like this:
var newMarker = markers.createMarker(Number(markerInfo.in));
newMarker.name = markerTitle;
newMarker.comments = markerComment;
newMarker.end = Number(markerInfo.out);
if (markerInfo.colorType) {
newMarker.setColorByIndex(Number(markerInfo.colorType));
}Since createMarker() returned the marker object, I could immediately modify properties like color.
In UXP, however, markers are added using actions.
When I use createAddMarkerAction, I’m not sure if there’s a way to:
-
get the newly created marker object back, or
-
keep a reference to it after creation.
const project = await ppro.Project.getActiveProject();
let success = false;
project.lockedAccess(() => {
for (let i = 0; i < markerInfo.length; i++) {
const markInfo = markerInfo[i];
const duration =
markInfo.out && markInfo.in
? ppro.TickTime.createWithSeconds(markInfo.out - markInfo.in)
: ppro.TickTime.TIME_ZERO;
success = project.executeTransaction((compoundAction: any) => {
const addMarkerAction = markers.createAddMarkerAction(
markInfo.title || '',
markInfo.markerType || ppro.Marker.MARKER_TYPE_COMMENT,
ppro.TickTime.createWithSeconds(markInfo.in || 0),
duration,
markInfo.comments || ""
);
compoundAction.addAction(addMarkerAction);
// After adding a marker, is there a way to retrieve it?
// const markerList = markers.getMarkers();
// const changeMarker = markerList[markerList.length - 1];
// if (changeMarker) {
// const changeColorAction =
// changeMarker.createSetColorByIndexAction(
// markInfo.colorType || ppro.Marker.MARKER_COLOR_NONE
// );
// compoundAction.addAction(changeColorAction);
// }
});
}
});Questions:
-
After executing
createAddMarkerAction, is there any supported way in UXP to obtain the newly created marker object? -
Is it safe to assume the newly added marker is always the last item in
markers.getMarkers()? -
If so, do I need to run another
lockedAccess()/ transaction to change its color afterward? -
Or is there a recommended way to set marker color at the time of creation (similar to CEP) so that a second action is unnecessary?
I’m trying to find the best practice for replicating CEP-style marker creation and modification in UXP.
