Help with track grouping

richjo100 wrote on 11/9/2004, 3:52 AM
Hello,

I want to chagne the Vegas Import XML script that comes bundled with it to allow grouping of track events. At the moment if you have some tracks that are grouped and then export the xml (using the Vegas script) and then re-import them (using the vegas script) you lose the grouping. At the moment I have chagned the following code but I get an Cast Error

In Import Track Event I have added the *********** lines

==========================================================

function ImportTrackEvent(parent : XmlElement, events : TrackEvents) {
var trackEvent : TrackEvent = null;
var audioEvent : AudioEvent = null;
var videoEvent : VideoEvent = null;

//set up variable for groups
var allGroups : TrackEventGroups = Vegas.Project.Groups; *************

if (parent.Name == "AudioEvent") {
audioEvent = new AudioEvent();
trackEvent = TrackEvent(audioEvent);
} else if (parent.Name == "VideoEvent") {
videoEvent = new VideoEvent();
trackEvent = TrackEvent(videoEvent);
}
events.Add(trackEvent);

.................
all try/catch clauses etc here.....
..........................
//if got audioEvent then add to group
if (audioEvent != null) ***********
allGroups.Add(audioEvent); ***********
//if got video event then add to group
if (videoEvent != null) *************
allGroups.Add(videoEvent); *************
}


I get a cast exception. If I comment out the audioEvent then the script runs but the groups arent set.

Can anyone help me set this up

Thanks
Richard

Comments

jetdv wrote on 11/9/2004, 6:33 AM
Try changinging your how "allGroups" is defined. You need it to be your "new group"

var allGroups : TrackEventGroups = new TrackEventGroup();
Vegas.Project.Groups.Add(allGroups);

Now the two additions to "allGroups" should work.
richjo100 wrote on 11/9/2004, 10:30 AM
Hi JetDV,
Thanks for the reply. I have tried what you said and the program has stopped crashing. However it does not group the clips.

The program is

function ImportTrackEvent(parent : XmlElement, events : TrackEvents) {
var trackEvent : TrackEvent = null;
var audioEvent : AudioEvent = null;
var videoEvent : VideoEvent = null;

var allGroups : TrackEventGroup = new TrackEventGroup();*************
Vegas.Project.Groups.Add(allGroups);****************

if (parent.Name == "AudioEvent") {
audioEvent = new AudioEvent();
trackEvent = TrackEvent(audioEvent);
} else if (parent.Name == "VideoEvent") {
videoEvent = new VideoEvent();
trackEvent = TrackEvent(videoEvent);
}
events.Add(trackEvent);

.....all the tries etc.......

if (audioEvent != null){ *************
allGroups.Add(audioEvent); **********
} ***********
if (videoEvent != null){ **********
allGroups.Add(videoEvent); *********
} ***********

Again all the ***** is my extra code. Have I got the concept of allGroups wrong? Is it an array of the groupings? Am I doing this in the wrong place in the xml script?

Thanks for any help
Richard

jetdv wrote on 11/9/2004, 11:23 AM
Your view is probably not so much "wrong" as "misunderstood"

Try this change:

if (parent.Name == "AudioEvent") {
audioEvent = new AudioEvent();
trackEvent = TrackEvent(audioEvent);
} else if (parent.Name == "VideoEvent") {
videoEvent = new VideoEvent();
trackEvent = TrackEvent(videoEvent);
}
events.Add(trackEvent);
allGroups.Add(trackEvent);

.....all the tries etc.......

if (audioEvent != null){ *************
********** <-- removed from here
} ***********
if (videoEvent != null){ **********
********* <-- removed from here
} ***********



The items being grouped should be TRACK events.
richjo100 wrote on 11/10/2004, 10:09 AM
Thanks for the reply again jetdv.
I have tried what you said.

I have the following declaration inside the "ImportTrackEvent"

var allGroups : TrackEventGroup = new TrackEventGroup();
Vegas.Project.Groups.Add(allGroups);

and have added

allGroups.Add(trackEvent);

However when it imports then they are not grouped. It seems to have had no effect.

I thought it might be because I was redeclaring allGroups every time the function was accessed so I took this outside of the function and I now get a cast exception?
I have tried using allGroups[i] and changing i appropriately but this isnt working either?

Thanks for any help
Richard
jetdv wrote on 11/10/2004, 10:54 AM
Move BOTH of the top two lines outside of the loop.

Sure you don't have "Ignore Event Grouping" turned on???
richjo100 wrote on 11/11/2004, 2:20 AM
Thanks JetDV

When I declared
var allGroups : TrackEventGroup = new TrackEventGroup();
Vegas.Project.Groups.Add(allGroups);
I get an error

So I have declared
var allGroups : TrackEventGroup = null;
at the top and then in

ImportTrackEvents I have declared it

allGroups = new TrackEventGroup();
Vegas.Project.Groups.Add(allGroups);

to define allGroups.

I have then still got

allGroups.Add(trackEvent);

in ImportTrackEvent

Hope this makes sense!

It sort of works. The grouping is now long the track. Sorry if I have not made myself clear but I want to group each individual video and audio track so I can move them around teh timeline. Do I have to use allGroups as an array?

Thanks for your help so far JetDV
jetdv wrote on 11/11/2004, 6:21 AM
No. The creation of the new group will have to be moved back inside the loop. Sounds like you're wanting to create a BUNCH of groups - not just one. Move these two lines back inside the loop:

allGroups = new TrackEventGroup();
Vegas.Project.Groups.Add(allGroups);


In reality, "allGroups" is more of a misnomer. Instead using a name such as "thisGroup" would be more appropriate.
richjo100 wrote on 11/11/2004, 7:03 AM
Hi JetDV
Thanks for the help!
I think I have already tried to put the declaration inside the loop. I will have a look over the next half hour. I think the loop looks through each track one by one. Therefore there is never any overlap between the video track and audio track. It does the all the video then does all teh audio. I think I will just end up creating four groups, if I have a video track with 2 clips and an audio track with two clips. You are correct though in that I need to create several groups. i want to group the relevatn video and audio tracks. In the case of two audio and two video clips i want two groups with the one vid/audio in each
thanks for your help so far

Richard
richjo100 wrote on 11/11/2004, 10:38 AM
Ive solved it. I have to write an extra function and then loop through each event in each track. I will post the code tomorrow when i have fully tested it.
Thanks for your help JetDV
Richard
richjo100 wrote on 11/12/2004, 1:20 AM
Hi
If I want to group the track events in track 0 and track 1 then the following code can be used:

=============================================================

var trackVideo = Vegas.Project.Tracks[0];
var trackAudio = Vegas.Project.Tracks[1];

var videoEnum = new Enumerator(trackVideo.Events);
var audioEnum = new Enumerator(trackAudio.Events);

while (!videoEnum.atEnd()){
var allGroups : TrackEventGroup = null;
allGroups = new TrackEventGroup();
Vegas.Project.Groups.Add(allGroups);

var videoTrack : TrackEvent = TrackEvent(videoEnum.item());
var audioTrack : TrackEvent = TrackEvent(audioEnum.item());

allGroups.Add(videoTrack);
allGroups.Add(audioTrack);

videoEnum.moveNext();
audioEnum.moveNext();
}


=============================================================

This can be added to the end of the ImportXML Vegas script so that any clips imported will now be grouped.

Richard