Comments

JohnnyRoy wrote on 10/25/2008, 7:03 AM
I would expect the index to be read only because normally you would want to manipulate the collection itself but there seems to be a bug in the script API because any call to Tracks.Insert() yields an exception:

The code:

vegas.Project.Tracks.Insert(0, new VideoTrack());

Should work but it yields:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: Specified method is not supported.
at Sony.Vegas.BaseList`1.Insert(Int32 index, T item)
at EntryPoint.FromVegas(Vegas vegas)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Sony.Vegas.ScriptHost.ScriptManager.Run(Assembly asm, String className, String methodName)
at Sony.Vegas.ScriptHost.CodeDomScriptManager.Run()
at Sony.Vegas.ScriptHost.RunScript(Boolean fCompileOnly)

The same is true if you use the follwoing code to swap two tracks:

Track tmp = vegas.Project.Tracks[0];
vegas.Project.Tracks[0] = vegas.Project.Tracks[1];
vegas.Project.Tracks[1] = tmp;

I have also tried with the remaining two methods that do work (i.e., Add() and RemoveAt()) but the behavior of the collection is one of ownership. RemoveAt() implies Destroy() so once you remove a track it cannot be used again for an Add() because it is destroyed as part of the remove operation. This is perfectly acceptable behavior considering that tracks cannot exist outside of a project but it does prohibit one from manipulating the collection.

Given the current behavior, what we need are additional methods to change the order of the collection. Until this gets addressed, I would say it is impossible to change the order of tracks. :(

~jr
Rosebud wrote on 10/25/2008, 10:25 AM
Thx JR.
I also tried the “Insert” method with same result.
So, I got the same conclusion as you.

Any comment from SCS would be welcome.
Teetow wrote on 10/29/2008, 6:09 PM
Did you try Track.DisplayIndex? I'm not at work now, but I would venture a guess that's what you're after.
2G wrote on 10/20/2009, 11:09 AM
Just encountered the same problem. Track.DisplayIndex is read-only as well. I still don't see a way to move existing tracks around. However, on the constructor of VideoTrack, you can specify an index. Then just use the tracks.Add method. Kinda convoluted in my opinion. But does put the track where you want it.

new VideoTrack( Vegas.Projects.Tracks.Count ) will put it at the end.