Skip to main content
New Participant
October 11, 2019
Answered

Add a track in a sequence, extendscript

  • October 11, 2019
  • 7 replies
  • 6286 views

Hi,

I'm trying to find a way to add a track in a sequence with a script. (as the last commands from the menu list "sequences", add or delete tracks).

Fab.

Correct answer guntramp26642460

Hey Bruce,

thanks for your reply 🙂

 

The problem was, that using the remove functions with QEDom was causing an audioTrack to be deleted, which was not empty.

I am not really sure why this happened, but after cleaning up my code a little the problem did not seem to occur anymore.

In this case, I am sending commands to AfterEffects via BridgeTalk, because I thought we do not need an extra AE-panel for the usecase.

This works pretty neat, but I forgot some simple things, like "do not import footage if it already exists" - or "do not insert footage to a layer if it is already in there"....
So after cleaning up it seems to be good.

I must emphasize that I did not try that on newer versions, as we are still stuck to the 2019 versions (PPRO & AEFT), and I also did not try on Mac yet (I test stuff on the Mac after it is running in Windows 😉 ).

I will keep an eye on the remove functions (I know it is not part of the officially supported API), and test stuff in newer CC versions in the future...

(To me, Eli_Portell-TUVs1qs answer seems already correct to the OP question - I just wanted to add some little more detailed code how to get a sequence if you do not want to work with the currently active one, and after I posted it I saw the other post by RajinderSingh where he made a separate post with his question, because it is kind of a different question than the one which was asked here...).

 

7 replies

bbb_999
Adobe Employee
Adobe Employee
January 20, 2022

There's no function for adding (or removing) tracks, in the PPro ExtendScript DOM.

Perhaps you could create a new sequence from a template?

guntramp26642460
guntramp26642460Correct answer
Inspiring
January 21, 2022

Hey Bruce,

thanks for your reply 🙂

 

The problem was, that using the remove functions with QEDom was causing an audioTrack to be deleted, which was not empty.

I am not really sure why this happened, but after cleaning up my code a little the problem did not seem to occur anymore.

In this case, I am sending commands to AfterEffects via BridgeTalk, because I thought we do not need an extra AE-panel for the usecase.

This works pretty neat, but I forgot some simple things, like "do not import footage if it already exists" - or "do not insert footage to a layer if it is already in there"....
So after cleaning up it seems to be good.

I must emphasize that I did not try that on newer versions, as we are still stuck to the 2019 versions (PPRO & AEFT), and I also did not try on Mac yet (I test stuff on the Mac after it is running in Windows 😉 ).

I will keep an eye on the remove functions (I know it is not part of the officially supported API), and test stuff in newer CC versions in the future...

(To me, Eli_Portell-TUVs1qs answer seems already correct to the OP question - I just wanted to add some little more detailed code how to get a sequence if you do not want to work with the currently active one, and after I posted it I saw the other post by RajinderSingh where he made a separate post with his question, because it is kind of a different question than the one which was asked here...).

 

guntramp26642460
Inspiring
November 8, 2022

When using 

addTracks()

from QEDom, you might see that it inserts a videoTrack at the beginning (so there will be a new videoTrack[0] and all others are pushed above it).

 

When using 

addTracks(3)

it will prepend 3 videoTracks into the videoTracks array!

 

Now, if you set a second parameter, the desired number of videoTracks (first parameter) will be inserted after this index:

addTracks(2, 3)

inserts two videoTracks after index 3, so there will be a new empty videoTrack[4]!

 

There are even more parameters (badly explained in the object-model-viewer inside ExtendScriptToolkit -> search for QESequence, see that addTracks() accepts a bunch of number parameters...).

 

This is good if you do not want to add audioTracks "in the background" while adding a new videoTrack (which is done automatically by default):

addTracks(1, 3, 0)

will add one new videoTrack after videoTrackIndex 3, and NOT add an audioTrack!

 

(I am not sure about the fourth parameter and further ones, if you execute

addTracks(0, 0, 1, 3)

it will prepend an audioTrack to the beginning of audioTracks, no matter the fourth parameter...)

Eli Portell9548531
Inspiring
October 15, 2019

app.enableQE();

var seq = qe.project.getActiveSequence();

Then you will have access to:

addTracks()
removeTracks()
removeVideoTrack()
removeAudioTrack()
removeEmptyVideoTracks()
removeEmptyAudioTracks()

 

No documentation on QE. Just kinda got test things out.

 

Might also help to know that you target tracks by using:

seq.getVideoTrackAt(x);

JapinderSandhu
Inspiring
July 25, 2020

Is there a way to get a specific sequence with the qe dom rather than just the active sequence? 

app.enableQE();
var seq = qe.project.getActiveSequence();
Then you will have access to: addTracks()

the problem here is im not trying to get the active sequence
 
I am trying to get sequence by a specific ID
 
This fails:

 

	for (var i = 0; i < qe.project.sequences.numSequences; i++) {
			var seq = qe.project.sequences[i];
			if (seq.sequenceID === newSeqID){
				var newSeq = seq;
			} 
		}



This works:

	for (var i = 0; i < app.project.sequences.numSequences; i++) {
			var seq = app.project.sequences[i];
			if (seq.sequenceID === newSeqID){
				var newSeq = seq;
			} 
		}​

 

guntramp26642460
Inspiring
January 20, 2022
quote

Is there a way to get a specific sequence with the qe dom rather than just the active sequence? 

 

This might help when trying to find a sequence by id:

var removeEmptyAudioAndVideoTracksInVersionSequence = function removeEmptyAudioAndVideoTracksInVersionSequence(sequenceId) {
  app.enableQE();
  var bin = getBinFromQEDomByPath('mybin/sequences');
  if (bin) {
    bin.flushCache();
    for (var index = 0; index < bin.numSequences; index++) {
      sequence = bin.getSequenceAt(index);
      if (sequence && sequence.guid === sequenceId) {
        sequence.removeEmptyAudioTracks();
        sequence.removeEmptyVideoTracks();
        return 'true';
      }
    }
  }
  return 'error: bin not found!';
};

var getBinFromQEDomByPath = function getBinFromQEDomByPath(binPath) {
  app.enableQE();
  var qeProject = qe.project;
  // remove last char if it is a slash
  binPath = binPath.replace(/\/$/, '');
  var binPathAsArray = binPath.split('/');
  // start at root level
  var bin = qeProject;
  // go as deep as the binPath is
  for (var binNameIndex = 0; binNameIndex < binPathAsArray.length; binNameIndex++) {
    for (var currentBinIndex = 0; currentBinIndex < bin.numBins; currentBinIndex++) {
      var binToFind = bin.getBinAt(currentBinIndex);
      if (binToFind.name === binPathAsArray[binNameIndex]) {
        // return it because it is the last bin of the path from binPath
        if (binNameIndex === binPathAsArray.length - 1) {
          return binToFind;
        }
        // it was the next bin of the path from binPath
        bin = binToFind;
        // stop inner loop, continue with outer loop...
        break;
      }
    }
  }
  // not found
  return null;
};

 

I still have a sporadic problem, that sometimes audioTracks are removed by ``removeEmptyAudioTracks()`` which are not empty 😞

Can anyone confirm this?


(at least in Windows, PPRO 2019 - did not test with other versions yet...)

Ann Bens
Community Expert
October 11, 2019

Yeah got it now. Added SDK to your post for better help.

 

New Participant
October 11, 2019

hum hum, sorry it was obvious to me with the title of my post... I want to do this in a script, with extendscript.

Ann Bens
Community Expert
October 11, 2019

You either use the dropdown menu or rightclick on the HEADER in the timeline or set up KBSC.

 

MarekMularczyk
Community Expert
October 11, 2019

And then in the dialogue box choose whether you want to add Video or Audio tracks and how many.

Adobe Community ExpertAdobe Certified Professional
MarekMularczyk
Community Expert
October 11, 2019

To add Tracks in a Sequence, right-click in the empty area of your Timeline and choose Add Tracks...

Adobe Community ExpertAdobe Certified Professional