automator-plus/tutorials

Setting nextClip.start = thisClip.end

louwjlabuschagne opened this issue · 8 comments

Hi,hope you are well.

can you please see this one line code of premiere pro scripting?
I followed your tut. And trying this.

nextClip.start = thisClip.end.ticks;

I just want next clip will be start at the end of first clip. But having
this error at extendscript ( Cannot set property start.)

here is the full code.

var project = app.project;
var sequence = project.activeSequence;

var videoTracks = sequence.videoTracks;
var thisTrack = videoTracks[0];
var clips = thisTrack.clips;
var thisClip = clips[0];
var nextClip = clips[1];

nextClip.start = thisClip.end.ticks;

Thanks

From the TypeScript definitions in Adobe's official starter code (https://github.com/Adobe-CEP/Samples/blob/master/PProPanel/jsx/PremierePro.14.0.d.ts) it appears that the start Time object is read-only,

Screenshot 2021-02-16 at 13 57 58

that is why you can't set it.

However, I tried setting the end Time object of a clip and it also didn't work - so either the TypeScript definition is outdated, or there is another way to set the Time Object of a Track Item. @bbb999 any ideas? I've tried

newTime = new Time();
newTime.seconds = 20;
nextClip.end = newTime;

and

nextClip.end.seconds = 20;

but neither work - is it fair to assume that both start and end Time objects of a TrackItem is read-only?

Regarding the initials question about how to insert a clip next to the previous clip, here is a solution that adds an additional clip either with the insert or overwrite method. The unfortunate consequence is that you have to clean up after yourself and delete the original clip, here is some sample code:

var videoTrackNr = 0;
var audioTrackNr = 0;
var overwrite = true;

var project = app.project;
var sequence = project.activeSequence;

var videoTracks = sequence.videoTracks;
var track = videoTracks[videoTrackNr];
var clips = track.clips;
var thisClip = clips[0];
var nextClip = clips[1];
var nextClipAudio = sequence.audioTracks[audioTrackNr].clips[1];

var thisClipEnd = thisClip.end;


var nextClipProjectItem = nextClip.projectItem;

if (overwrite) {
  sequence.overwriteClip(
    nextClipProjectItem,
    thisClipEnd,
    videoTrackNr,
    audioTrackNr
  );
} else {
  sequence.insertClip(
    nextClipProjectItem,
    thisClipEnd,
    videoTrackNr,
    audioTrackNr
  );
}

nextClip.remove(false, true); // inRipple, inAlignToVideo
nextClipAudio.remove(false, true); // inRipple, inAlignToVideo

Result of running the above code snippet.

move-clip-output

Wow it works.
I have no words to thank you Louwrens.
I must quit using PR if i could not do this.
I usually do it using after effects but Now premiere using GPU for rendering and it's much more faster. Thats why I'm trying shift my works to pr.

Thank you so much sir.

I wish you to make a video about this in your channel as well.

@shakilmax I've added a ticket on our video backlog: #21

We've got a few other video's lined up next, but once we are done with them we'll give #21 a go... 👍

Fougl commented

Hi guys,

I believe its not read only. For example, app.project.sequences[0].videoTracks[2].clips[0].start=3, puts the clip start at 3 seconds for me. Also, in the extend script pdf premiere pro scripting guide suggests that it is read/write.

Best, Ales

Thanks @Fougl for the update.... ☺️

When I use Xclip[0].end = 3, it works well , but also throws an error
so i do it with whese code.

// Move Next Clip To Previous End
var sequence = app.project.activeSequence;  // active sequence
var clip1 = sequence.videoTracks[1].clips[0]  // first clip
var clip2 = sequence.videoTracks[1].clips[1]  // second clip

var new_end_time = clip2.end.seconds - clip2.start.seconds + clip1.end.seconds  // second clip new end time , this way, dont change the clip duration

// use "clip.start" or "clip.end" will throw an error. I dont know why.

try {
    clip2.start = clip1.end.seconds
} catch (error) {

    try {
        clip2.end = new_end_time
    } catch (error) {
    }
}```