subclips and the export/importXML scripts

Gary_G wrote on 5/25/2005, 12:17 AM
I've been hacking the ImportXML script so I can just import the media bins from a project and have noticed that the ImportXML script doesn't place sublips into the media bins. This happens with the original script not just my hack. Has anybody else noticed this behaivour? Any clues as to what might need adjusting?

Thanks
Gary

Comments

Gary_G wrote on 5/26/2005, 12:08 AM
I've worked out where the problem in the ImportXML script is, but not knowing jscript I've been running a little blind. I first isolated the problem in this snippet of code that imports the media bins

***
function ImportMediaBin(elt : XmlElement, bin : MediaBin, pool : MediaPool) {
if (null == elt) return;
var enumMedia : IEnumerator = elt.SelectNodes("./MediaRef").GetEnumerator();
while (enumMedia.MoveNext()) {
var mediaElt : XmlElement = XmlElement(enumMedia.Current);
var mediaKey : String = mediaElt.InnerText;
//Testing message box
MessageBox.Show("mediaKey outer: " + mediaKey); <<<<my msg box
var media : Media = FindMedia(pool, mediaKey);
if (null != media) {
//Testing message box
MessageBox.Show("mediaKey inner: " + mediaKey); <<<<my msg box
bin.Add(media);
}
}
***

Standard clips and generated media pass the "if(null != media)" test but subclips don't. Looking through the code it looks as if a key doesn't get constructed for subclips.

Here's the code that imports the standard clips and generated media

***

function ImportMedia(elt : XmlElement, pool : MediaPool) {
var key : String = ChildString(elt, "KeyString");
MessageBox.Show("keyString: " + key); <<< my testing msg box
var media : Media = null;
if (IsGeneratedMediaKey(key)) {
var effectElt : XmlElement = elt["Effect"];
if (null == effectElt) return;
var plugInName : String = ChildString(effectElt, "PlugIn");
var plugIn : PlugInNode = Vegas.Generators.GetChildByName(plugInName);
if (null == plugIn) return;
media = new Media(plugIn);
theGeneratedMediaKeys[key] = media.KeyString; <<< function call to create
} else { a key for generated
media = new Media(key); media
}
try { media.UseCustomTimecode = ChildBoolean(elt, "UseCustomTimecode"); } catch (e) { }
if (media.IsOffline() || media.UseCustomTimecode) {
media.TimecodeIn = ChildTimecode(elt, "TimecodeIn");
}
if (media.IsOffline()) {
media.TimecodeOut = ChildTimecode(elt, "TimecodeOut");
}
ImportMediaInternal(elt, media);
}

***

From this I can see that the script has to create a searchable key for generated media but not standard media.

Looking at the subclip import function it is missing this function.

***
function ImportSubclip(elt : XmlElement, pool : MediaPool) {
var parentMediaKey : String = ChildString(elt, "ParentMedia");
var parentMedia : Media = FindMedia(pool, parentMediaKey);
if (null == parentMedia)
throw "could not find subclip's parent media: " + parentMediaKey;
var start : Timecode = ChildTimecode(elt, "Start");
var length : Timecode = ChildTimecode(elt, "Length");
var reverse : Boolean = false;
try { reverse = ChildBoolean(elt, "IsReversed"); } catch (e) {}
var displayName : String = null;
try { displayName = ChildString(elt, "FilePath"); } catch (e) {}
var subclip : Subclip = new Subclip(parentMediaKey, start, length, reverse, displayName);
ImportMediaInternal(elt, subclip);
}

***

something like "theGeneratedMediaKeys[key] = subclip .KeyString;" has to go after the "var subclip..." line plus creating the value for key near the top of the function "var key : String = ChildString(elt, "KeyString");". despite various efforts I couldn't get this to work. By accident I did eventually get the following function to work

***

function ImportSubclip(elt : XmlElement, pool : MediaPool) {
var key : String = ChildString(elt, "KeyString");
var media : Media = null;
media = new Media(key);
theGeneratedMediaKeys[key] = media.KeyString;
ImportMediaInternal(elt, media);
}

***

The keystrings in the exported XML file have the form
for normal media:-
E:\Library\quotes\test\concert.avi
for sublips:-
META:\SubClip\{E:\Library\quotes\test\concert.avi} (1)[195611927][52969541][0]

From the script docs I can see why the keyString for the normal media will work, but not for the subclip. Is it using an undocumented constuctor?

On my modest tests it seems to be working correctly, so perhaps I shouldn't be so perplexed - but am I missing something that will cause problems down the track.

Thanks
Gary