Need help placing a new audio event.

ponchoman1 wrote on 8/16/2004, 5:58 PM
Hi all,
Can someone help me with the following peice of a script. Basically, I'm trying to place a audio file into the project at the current cursor location. I am using vbscript. Thx......


dim newMedia as new Media("C:\audio\backup\QCELP\081004_A_E3.wav")
dim newStream = newMedia.Streams.GetItemByMediaType(MediaType.Audio, 0)
dim newEvent as new AudioEvent(VegasApp.Cursor, newStream.Length)

VegasApp.Project.Tracks(2).Events.Add(newEvent)
dim take as new Take(stream)
newEvent.Takes.Add(take)

I get the follwing error when I run this....

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object variable or With block variable not set.
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)

Comments

rcampbel wrote on 8/16/2004, 6:25 PM
Well, this is just a guess. Has the VegasApp variable been set to the Vegas object? I also don't see a definition of stream in "new Take(stream)". If either of these are unassigned, this can cause a NullReferenceException.

Randall
jetdv wrote on 8/16/2004, 6:36 PM
The first four lines look good to me. What happens if you remove these two lines:

dim take as new Take(stream)
newEvent.Takes.Add(take)

Or, at least, change "stream" to "newStream" which is how you defined the variable.

dim take as new Take(newStream)
newEvent.Takes.Add(take)

ponchoman1 wrote on 8/17/2004, 9:21 AM
If I remove the last 4 lines as follows.....

dim newMedia as new Media("C:\audio\backup\QCELP\081004_A_E3.wav")
dim newStream = newMedia.Streams.GetItemByMediaType(MediaType.Audio, 0)

'dim newEvent as new AudioEvent(VegasApp.Cursor, newStream.Length)
'VegasApp.Project.Tracks(2).Events.Add(newEvent)
'dim take as new Take(newStream)
'newEvent.Takes.Add(take)

I get no error. However, when I include the 3rd line as follows.....

dim newMedia as new Media("C:\audio\backup\QCELP\081004_A_E3.wav")
dim newStream = newMedia.Streams.GetItemByMediaType(MediaType.Audio, 0)
dim newEvent as new AudioEvent(VegasApp.Cursor, newStream.Length)

'VegasApp.Project.Tracks(2).Events.Add(newEvent)
'dim take as new Take(newStream)
'newEvent.Takes.Add(take)

I get the error. Any ideas?
jetdv wrote on 8/17/2004, 9:33 AM
Try this instead:


dim newMedia as new Media("C:\audio\backup\QCELP\081004_A_E3.wav")
dim newStream = newMedia.Streams.GetItemByMediaType(MediaType.Audio, 0)
dim newEvent as new AudioEvent(VegasApp.Cursor, newMedia.Length)

(note: newMedia in the last line instead of newStream)
ponchoman1 wrote on 8/17/2004, 1:27 PM
That part works. Thanks for the help. Now I'm at the point where a blank event is placed on the indicated track. However, I can't seem to put the audio stream into the event. I get an error when I include the last line in the script.


dim newMedia as new Media("C:\audio\backup\QCELP\081004_A_E3.wav")
dim newStream = newMedia.Streams.GetItemByMediaType(MediaType.Audio, 0)
dim newEvent as new AudioEvent(VegasApp.Cursor, newMedia.Length)

VegasApp.Project.Tracks(2).Events.Add(newEvent)
dim take as new Take(newStream)
'newEvent.Takes.Add(take)

Here is the error.....

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: media stream not specified
jetdv wrote on 8/17/2004, 2:15 PM
Could it be a problem with using the same name? What if you use newTake instead?

VegasApp.Project.Tracks(2).Events.Add(newEvent)
dim newTake as new Take(newStream)
'newEvent.Takes.Add(newTake)

Alternately, have you checked to verify that newStream is NOT null? (It *shouldn't* be)

ponchoman1 wrote on 8/17/2004, 3:19 PM
That worked! Thank you so much for your help!!!!