Generated Media CustomParameter problem for titles

Rob J wrote on 4/10/2016, 3:08 PM
Dear Vegas Pro scripters,

I'm working on a C# script that takes the labels of regions and adds a Titler Pro title for each region.

So far it successfully adds a new video track, adds events in the correct places and also the generated media. The problem is the final step of the configuration.

The "CustomData" parameter contains the TitlerPro XML configuration of the title. The script extracts this into an XML document and replaces the necessary parts of the configuration. At this point it attempts to assign the XML back to the CustomData parameter:


PlugInNode pluginNB3 = myVegas.Generators.FindChildByName("NewBlue Titler Pro 3 - OpenFX");
// Creation of Media item performed here.
Media item = new Media(pluginNB3);
OFXEffect effect = item.Generator.OFXEffect;

OFXCustomParameter custo = effect.FindParameterByName("CustomData") as OFXCustomParameter;
XmlDocument custoDoc = new XmlDocument();
custoDoc.LoadXml(custo.Value);
XmlNode custoTitleNode = custoDoc.SelectSingleNode("/title");

// Customisation of XML code omitted here, but functions as expected.

StringBuilder sb = new StringBuilder(300000);
using (StringWriter sw = new StringWriter(sb))
{
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Encoding = Encoding.ASCII;
xmlSettings.OmitXmlDeclaration = true;
xmlSettings.WriteEndDocumentOnClose = true;
xmlSettings.Indent = true;
xmlSettings.Async = false;
xmlSettings.CheckCharacters = true;
using (XmlWriter tx = XmlWriter.Create(sw, xmlSettings))
{
custoTitleNode.WriteTo(tx);
}
string xmlString = sw.ToString();

MessageBox.Show("producedXml: " + xmlString); // XML String is complete and contains all expected content.

custo.Value = xmlString;
MessageBox.Show("After asignment: " + custo.Value); // XML String is truncated, normally the same length by varies within about 10 characters.
}


The first message box contains the correct XML as I expect it to be created. After assigning it to the custo.Value and then displaying that content, the value is truncated.

Is this a problem:
a) in my code (do I need to allocate memory differently or assign the value in a different way?)
b) something controlled by the parameters in Vegas Pro?
c) Titler Pro 3 or 4 behaviour on notification that this parameter is modified?

I am new to C#, but experienced at programming in other languages.

Thank you for your time in advance!

System: Windows 10 64-Bit, Vegas Pro 13 Build 453 64-Bit, NewBlueFX TitlerPro3 OpenFX.

Comments

VEGASNeal1 wrote on 4/13/2016, 10:29 AM
Some notes:

The phrase "allocate memory differently" is confusing. In C# 'new' creates a new object instance. Any memory allocation that occurs is handled automatically, not something the programmer typically needs to be concerned about.

StringBuilder sb = new StringBuilder(300000) ... there's typically no need to specify an explicit size. StringBuilder grows dynamically as needed.

The code creates instances of both a StringBuilder and StringWriter.
Unless you really need some of the methods that the StringWriter class provides, it is redundant. Just use the StringBuilder in XmlWriter.Create(...) in place of the StringWriter.

If you do need StringWriter, then the StringBuilder can be removed as StringWriter will create one internally, automatically.

After the WriteTo(), tx.Flush() and tx.Close() should probably be called; but as you're writing to a memory buffer, it is really just a matter of form, I doubt it will affect the script's operation.

The key problem is I believe the assignment of the string to custo.Value,
I ran some trials using the Sony Titles & Text generator. When using the same assignment to provide the text for the effect, only 4000 characters are copied.
The textbox in the effect UI, lets me type more than this, so either the plugin, or the portion of the program that transfers information to the plugin is imposing this unexpected 4000 character limit.
If you are also encountering a limit of 4000 characters than I'd suspect Vegas is imposing the limit. If you are encountering a limit of a different size than I'd suspect the plugin.

Hope you find something useful in these scattered notes.

Rob J wrote on 4/13/2016, 2:41 PM
Thank you very much gret127!

This is all interesting and useful information, I'll keep it in mind for this script and for future ones.

I've also received some support from the kind support team at NewBlueFX which means that I now have a script that can create these titles.

If anyone is interested, this is what I needed to do instead:

1. Make no modifications to the "CustomData" field ' (As expected, option A in my first post was the correct one).
2. Create Vegas Pro presets for the TitlerPro titles so that they appear in the Media Generators preset tab (for the OpenFX titler pro plugin).
3. Modify a different attribute ("Text") which has a specific XML format for defining paragraph text.


PlugInNode pluginNB3 = myVegas.Generators.FindChildByName("NewBlue Titler Pro 3 - OpenFX");
if (pluginNB3 == null) {
MessageBox.Show("No plugin found!");
return null;
}
Media item = new Media(pluginNB3, "My Preset Name");

OFXEffect effect = item.Generator.OFXEffect;
OFXStringParameter text = effect.FindParameterByName("Text") as OFXStringParameter;

XmlDocument textValDoc = new XmlDocument();
textValDoc.LoadXml(text.Value);

// Set the text in the attributes for each paragraph that you want to modify. This will depend on your preset.
XmlNode paragraph0 = textValDoc.SelectSingleNode("/Text/Paragraphs/Paragraph[@ID='0']");
paragraph0.Attributes["Text"].Value = "Content For First Paragraph";

XmlNode paragraph1 = textValDoc.SelectSingleNode("/Text/Paragraphs/Paragraph[@ID='1']");
paragraph1.Attributes["Text"].Value = "Content For Second Paragraph";

// Next 2 lines are required before each set value to "Text" parameter, thank you NewBlueFX.
OFXIntegerParameter isThemeBuilderCall = (OFXIntegerParameter)effect.FindParameterByName("IsThemeBuilderCall");
isThemeBuilderCall.Value = 1;

text.Value = textValDoc.OuterXml;
text.ParameterChanged();


This is working well for me and now I'm building a GUI to let me configure it as I would like.

Hopefully this is helpful for someone else out there as well.