Question about grouping in VBS

Vasia wrote on 4/27/2005, 5:53 AM
Hello everybody!
I have 3 tracks & 10 events
6 events on track(1)
2 events on track(2)
and 2 events on track(3)
I need to group 3 first events on track(1) + first event on track(2) & first event on track(3) - it must to be first group;

And 3 second events on track(1) + second event on track(2) & second event on track(3) - it must to be second group.
How can I do this?

Comments

jetdv wrote on 4/27/2005, 7:52 AM
You create a new group, add the group to the project, and then you add the proper events to that group. For example (in JScript):

var grp : TrackEventGroup = new TrackEventGroup();
Vegas.Project.Groups.Add(grp);
grp.Add(mynewEvent);
grp.Add(MyEvent);


Vasia wrote on 4/27/2005, 10:02 PM
Only problem is: I don't know how do it with VisualBasicScript. If just I Know how write to scripts on JS or can covert it to VBS I'll never ask.
Vasia wrote on 4/29/2005, 5:46 AM
Somebody can explain me how I can group in Visual Basic two events: track(0).event(0) and track(1).event(0)?
jetdv wrote on 4/29/2005, 6:47 AM
What if you translate to something like this and then start debugging from there?

Dim grp As New Sony.Vegas.TrackEventGroup()
Sony.Vegas.Project.Groups.Add(grp);
grp.Add(ev1);
grp.Add(ev2);


I have a background of programming in VB as well. However, all the scripts I've written have been in JScript (until I started using C#). The changeover from VBScript to JScript was really very small.

I might be able to help you get this going but it might be necessary to see your source. If you wanted, we could also help with the translation from VBScript to JScript.
Vasia wrote on 5/13/2005, 9:41 PM
>I might be able to help you get this going but it might be necessary
>to see your source. If you wanted, we could also help with the
>translation from VBScript to JScript.
It will be great!

I have a program DVSubMaker 1.3, that program can extract Date & Time from DV AVI and store this data as *.bmp - subpicture.
Also she create *.dvdt files whos contain information about length of subpictures (in milliseconds).
What I want to do with this scritp is add avi file into the timeline and add subpictures and then goup that files, again add avi and subpicures and again group theys like in project.

The script is work successfully
Herre is it

Option Strict off

imports System.IO
imports Sony.Vegas

Public Module MainModule
Public Sub Main()
Call AddTracks
Call AddEvents
End Sub

Public Sub AddTracks()
Dim STrack As New VideoTrack(0,"SubPicture")
Dim VTrack As New VideoTrack(1,"Video")
Dim ATrack As New AudioTrack(2,"Audio")
Dim BTrack As New AudioTrack(3,"BackMusic")

VegasApp.Project.Tracks.Add(VTrack)
VegasApp.Project.Tracks.Add(STrack)
VegasApp.Project.Tracks.Add(ATrack)
VegasApp.Project.Tracks.Add(BTrack)
End Sub

Public Sub AddEvents()
Dim NewTimecode As Timecode
Dim AviFileName As string
Dim AviFilePath As string
Dim i As Long
Dim NewMarker as Marker
Dim Wshell
Dim q

wshell = CreateObject("Shell.Application")
q = wshell.BrowseForFolder(&H0, "Select a path for *.avi files", &H1, 17)
AviFilePath = q.Self.Path
AviFilePath = AviFilePath & "\"

i = 0
Dim myDirectory As DirectoryInfo
myDirectory = New DirectoryInfo(AviFilePath)
Dim aFile As FileInfo
Dim AviFileNames(1) As String
For Each aFile In myDirectory.GetFiles("*.avi")
ReDim Preserve AviFileNames(i + 1)
AviFileNames(i) = aFile.Name
i = i + 1
Next
ReDim Preserve AviFileNames(i - 1)

Dim PrevEventEnd as Timecode
PrevEventEnd = Timecode.FromMilliseconds(0)

For i = 0 to UBound(AviFileNames)
Dim newMedia as new Media(AviFilePath & AviFileNames(i))
Dim newAPStream = newMedia.Streams.GetItemByMediaType(MediaType.Audio, 0)
Dim newVPStream = newMedia.Streams.GetItemByMediaType(MediaType.Video, 0)
Dim newVPEvent as new VideoEvent(PrevEventEnd, newMedia.Length)
Dim newAPEvent as new AudioEvent(PrevEventEnd, newMedia.Length)

VegasApp.Project.Tracks(1).Events.Add(newVPEvent)
VegasApp.Project.Tracks(2).Events.Add(newAPEvent)
dim newVPTake as new Take(newVPStream)
dim newAPTake as new Take(newAPStream)
newVPEvent.Takes.Add(newVPTake)
newAPEvent.Takes.Add(newAPTake)

Dim NewGroup As New TrackEventGroup()
VegasApp.Project.Groups.Add(NewGroup)
NewGroup.Add(newVPEvent)
NewGroup.Add(newAPEvent)
'Here I read information about length of subpictures from *.dvdt file
Dim PicFileName As String
Dim j as long
Dim AviName As String
j = 0
AviName = Left(AviFileNames(i), Len(AviFileNames(i)) - 4)
Dim FramesStrLen As Integer
Dim WholeString As String
Dim LenInfo(1) As Double
Dim k as Long

k = 1
FileOpen(1, AviFilePath & AviName & ".dvdt", OpenMode.Input)
Input(1, WholeString)
Input(1, WholeString)
FramesStrLen = InStr(1, WholeString, " ",1)
LenInfo(0) = CDbl(left(WholeString, FramesStrLen))
Do
ReDim Preserve LenInfo(k + 1)
Input(1, WholeString)
FramesStrLen = InStr(1, WholeString, " ",1)
If FramesStrLen = 0 Then
LenInfo(k) = CDbl(WholeString)
Else
LenInfo(k) = CDbl(left(WholeString, FramesStrLen))
End If
k = k + 1
Loop While Not EOF(1)
FileClose(1)

ReDim Preserve LenInfo(k - 1)

For k = Ubound(LenInfo) To 1 Step - 1
LenInfo(k) = LenInfo(k) - LenInfo(k - 1)
Next k

Dim PrevPicEnd As Timecode
PrevPicEnd = PrevEventEnd

Dim myPicDirectory As DirectoryInfo
myPicDirectory = New DirectoryInfo(AviFilePath)
Dim PicFile As FileInfo
For Each PicFile In myPicDirectory.GetFiles(AviName & "-????.bmp")
Dim newPMedia As New Media(AviFilePath & PicFile.Name)
Dim newPStream = newPMedia.Streams.GetItemByMediaType(MediaType.Video, 0)

Dim newPEvent As New VideoEvent(PrevPicEnd, Timecode.FromMilliseconds(LenInfo(j) * 40)) ' 40 = 1000ms / 25 fps
PrevPicEnd = Timecode.op_Addition(PrevPicEnd, Timecode.FromMilliseconds(LenInfo(j) * 40))
VegasApp.Project.Tracks(0).Events.Add(newPEvent)
dim newPTake as new Take(newPStream)
newPEvent.Takes.Add(newPTake)
NewGroup.Add(newPEvent)
j = j + 1
Next
PrevEventEnd = Timecode.op_Addition(PrevEventEnd, newMedia.Length)
Next i
End Sub

End Module

P.S.: Sorry what I don't answer so long.
johnmeyer wrote on 5/13/2005, 9:50 PM
This could be very useful. Thanks!