event.Copy function not working properly

rkelley wrote on 3/4/2004, 6:26 PM
Having a problem with the event.Copy function. Recently, I wrote a small script that does an event copy of an event then create a new event based upon that copy (using event.Copy). Unfortunately, for some reason, if the source event is split, the eventCopy function does not grab the correct source "frame".

The photosnapshot.js script is available here: http://www.sundancemediagroup.com/help/kb/kb_download.asp?id=380

To test the theory, simply open a new project, add an AVI file, the run the photosnapshot script. Next, split the source track the run the script again (with the Vegas cursor past the split). Place a marker at the beginning of the snapshot frame then another at the end of the photo event (just before the dissolve). Compare the two frames and you will notice the source frame is not the one copied to the photo track.

Could someone please help isolate why the eventCopy function is not working properly? I have been thru the code and don't see anything obvious. My only guess is an internal Vegas cursor is set each time the script gets run and I am not resetting it.

Thanks for any help,

-Ron

Comments

roger_74 wrote on 3/5/2004, 7:48 AM
I never tried the skeleton code I posted here on split events, so it could be my fault. :-)

Perhaps we should look at the active take offset for each event.

I have midterms in dotnet programming coming up, so I can't involve myself completely in this right now.
rkelley wrote on 3/5/2004, 12:00 PM
Roger,

I think I figured out the problem. Looks like the "NewPhotoEvent.ActiveTake.Offset" function has problems when you split the source track (among other issues). Instead of using that function, I took the long approach and did the following:

* Created a dummy track
* Copied the selected event to the dummy track
* Split the dummy track (Vegas.Cursor - currentEvent.Start)
* Copied event #2 (index 1) from the dummy track to the new Photo Track
* Deleted the dummy track

From what I can tell, the script runs exactly as it should - even if you split the source track 100 times. Here is the source code I wrote:
==========================================================================
var PhotoTrack : VideoTrack = GetVideoTrackByName("Photo Track", 0);
var BackgroundTrack : VideoTrack = GetVideoTrackByName("Background Track", 1);

// Create a dummy Event (because the NewPhotoEvent.ActiveTake.Offset function appears to have problems)
var dummyTrack : VideoTrack = new VideoTrack(Vegas.Project.Tracks.Count + 1, "Dummy");
Vegas.Project.Tracks.Add(dummyTrack);
var dummyEvent : VideoEvent = VideoEvent(currentEvent.Copy(dummyTrack,keepAtTimecode ? Vegas.Cursor : currentTrack.Length));
dummyTrack.Events[0].Split(Vegas.Cursor - currentEvent.Start);

// Create the new Photo Event & give it a place to start
// Note: Once the dummy track is split, it will contain 2 number
// of separate events - we want to get event 2 (index 1).
var NewPhotoEvent : VideoEvent = VideoEvent(dummyTrack.Events[1].Copy(PhotoTrack,keepAtTimecode ? Vegas.Cursor : PhotoTrack.Length));
NewPhotoEvent.Length = snapshotLength;

var BackgroundImage : VideoEvent = VideoEvent(dummyTrack.Events[1].Copy(BackgroundTrack,keepAtTimecode ? Vegas.Cursor : BackgroundTrack.Length));
BackgroundImage.Length = snapshotLength;

// Remove the dummy track when we are done
Vegas.Project.Tracks.Remove(dummyTrack);
==========================================================================

Hopefully you can read the code in this message. I will update the scripts on the Sundance site in a few minutes.

Hope your exams go well. And, sorry to keep bothering you about this...

-Ron
johnmeyer wrote on 3/5/2004, 2:48 PM
I think I figured out the problem. Looks like the "NewPhotoEvent.ActiveTake.Offset" function has problems when you split the source track

I have had all sorts of problems with this function. However, Ed (jetdv) helped me with it last June, and I was then able to use it in this script:

Delete n frames from event

The main problem is that both this function and the AdjustStartLength function seem to get confused about whether they are adjusting the event or the media contained in the event. The TRUE/FALSE flag in the AdjustStartLength never seemed to work right, and this affected how the ActiveTake.Offset worked.

Hopefully the few lines at the end of the above-referenced script may help you.
rkelley wrote on 3/5/2004, 6:51 PM
Thanks for the feedback. I have been driving myself crazy for about a week trying to fix this problem (I don't like it when other people post bad code for d/l). Glad to hear other people have run into the same issue as me (in a weird sort of way). I appreciate the time/energy the SoFo folks have put into the scripting mechansims (docs, etc). I just wish more example code existed so new javascript people (like myself) would have an easier time debugging code.

Thanks again for the info. I will look into your code in a few minutes.

-Ron
roger_74 wrote on 3/6/2004, 5:06 PM
Well, I said it could be my fault, and it was...

I never added the current event's offset to the new event.

so,
newEvent.ActiveTake.Offset = Vegas.Cursor - currentEvent.Start;
should be:
newEvent.ActiveTake.Offset = Vegas.Cursor - currentEvent.Start + currentEvent.ActiveTake.Offset;

That should do it I think. However, I still sometimes get the frame before the one I want (this is in PAL). The idiot way to fix it is to add half a frame to the offset. Or maybe it's a great way... haven't seen any issues yet.


Edit: To those wondering why I posted a single line of code out of thin air, the above code is from this discussion, and from rkelleys scripts at the sundance site.
jetdv wrote on 3/6/2004, 7:12 PM
Why wouldn't you simply use:

newEvent.ActiveTake.Offset = currentEvent.ActiveTake.Offset;

roger_74 wrote on 3/7/2004, 1:38 AM
The idea is to copy the event under the cursor and make a still of the exact frame on another track. So the new event's offset has to start where the cursor is on the current event.

From reading the description of rkelleys script it's easy to believe it just saves a snapshot or something, but it's much cooler than that. I was surprised.
jetdv wrote on 3/8/2004, 8:19 AM
Gotcha. The main difference with what I've done in the past is that I usually split the original event at that point. Then the "copy" begins in the same place without having to worry about the offset.