How do you edit text within the script? C# Vegas 14

george-w wrote on 7/30/2020, 1:12 PM

I want to be able to specify what text I want within the script.

Is there a way to edit text without adding a preset?

Here is my code so far, I am only able to use a preset in it.

 

                PlugInNode generator = myVegas.Generators.GetChildByName("Sony Titles & Text");

                Media media = new Media(generator, "(Default)");

                MediaStream stream = media.Streams[0];

                VideoEvent newEvent = new VideoEvent(myVegas.Transport.CursorPosition, Timecode.FromSeconds(2));

                myVegas.Project.Tracks[0].Events.Add(newEvent);

                Take take = new Take(stream);

                newEvent.Takes.Add(take);

Comments

jetdv wrote on 7/30/2020, 4:38 PM

Ok, you've added the event to the track. Now you have to actually change the text. Try something like this:

            Effect gEffect = newEvent.ActiveTake.Media.Generator;
            OFXEffect fxo = gEffect.OFXEffect;

            //Change the Text
            OFXStringParameter tparm = (OFXStringParameter)fxo.FindParameterByName("Text");
            RichTextBox rtfText = new RichTextBox();
            //rtfText.Rtf = tparm.Value;  //this will get the text that is already in the box if you want to change the existing text
            rtfText.Text = "Whatever you want the text to read";

            //You can change the font too
            rtfText.SelectAll();
            rtfText.SelectionFont = QLFont;

            //Set the text!
            tparm.Value = rtfText.Rtf;

            fxo.AllParametersChanged();

 

Taeyoung-Kim wrote on 12/6/2020, 9:27 PM

I want to set the font type, size, color and position of text.
I want to know about QLFont.
Please tell me how to set up QLFont.
Thank you.

jetdv wrote on 12/7/2020, 9:34 AM

In my case, the QLFont variable is a Windows form - FontDialog. You can open the FontDialog and select the font, font size, font style, etc...

        private void btnFont_Click(object sender, System.EventArgs e)
        {
            QLFont.ShowEffects = true;
            QLFont.ShowDialog();
            rtbQL.SelectAll();
            rtbQL.SelectionFont = QLFont.Font;
        }

 

Changing the alignment:

                OFXChoiceParameter tparm3 = (OFXChoiceParameter)fxo.FindParameterByName("Alignment");
                tparm3.Value = tparm3.Choices[3]; //Center Left
                fxo.AllParametersChanged();

 

Changing the position:

            OFXDouble2DParameter tparm2 = (OFXDouble2DParameter)fxo.FindParameterByName("Location");
            OFXDouble2D Pos;
            Pos.X = myX;
            Pos.Y = myY;
            tparm2.Value = Pos;

 

Taeyoung-Kim wrote on 12/8/2020, 6:54 PM

In my case, the QLFont variable is a Windows form - FontDialog. You can open the FontDialog and select the font, font size, font style, etc...

        private void btnFont_Click(object sender, System.EventArgs e)
        {
            QLFont.ShowEffects = true;
            QLFont.ShowDialog();
            rtbQL.SelectAll();
            rtbQL.SelectionFont = QLFont.Font;
        }

 

Changing the alignment:

                OFXChoiceParameter tparm3 = (OFXChoiceParameter)fxo.FindParameterByName("Alignment");
                tparm3.Value = tparm3.Choices[3]; //Center Left
                fxo.AllParametersChanged();

 

Changing the position:

            OFXDouble2DParameter tparm2 = (OFXDouble2DParameter)fxo.FindParameterByName("Location");
            OFXDouble2D Pos;
            Pos.X = myX;
            Pos.Y = myY;
            tparm2.Value = Pos;

 

Thank you very much!!! :)

How do I know which parameters go into FindParameterByName()? For example, "Text", "Alignment", "Location" ... etc.

Taeyoung-Kim wrote on 12/9/2020, 7:43 PM

In my case, the QLFont variable is a Windows form - FontDialog. You can open the FontDialog and select the font, font size, font style, etc...

        private void btnFont_Click(object sender, System.EventArgs e)
        {
            QLFont.ShowEffects = true;
            QLFont.ShowDialog();
            rtbQL.SelectAll();
            rtbQL.SelectionFont = QLFont.Font;
        }

 

Changing the alignment:

                OFXChoiceParameter tparm3 = (OFXChoiceParameter)fxo.FindParameterByName("Alignment");
                tparm3.Value = tparm3.Choices[3]; //Center Left
                fxo.AllParametersChanged();

 

Changing the position:

            OFXDouble2DParameter tparm2 = (OFXDouble2DParameter)fxo.FindParameterByName("Location");
            OFXDouble2D Pos;
            Pos.X = myX;
            Pos.Y = myY;
            tparm2.Value = Pos;

 

Thank you very much!!! :)

How do I know which parameters go into FindParameterByName()? For example, "Text", "Alignment", "Location" ... etc.

one more

Taeyoung-Kim wrote on 12/9/2020, 7:48 PM

In my case, the QLFont variable is a Windows form - FontDialog. You can open the FontDialog and select the font, font size, font style, etc...

        private void btnFont_Click(object sender, System.EventArgs e)
        {
            QLFont.ShowEffects = true;
            QLFont.ShowDialog();
            rtbQL.SelectAll();
            rtbQL.SelectionFont = QLFont.Font;
        }

 

Changing the alignment:

                OFXChoiceParameter tparm3 = (OFXChoiceParameter)fxo.FindParameterByName("Alignment");
                tparm3.Value = tparm3.Choices[3]; //Center Left
                fxo.AllParametersChanged();

 

Changing the position:

            OFXDouble2DParameter tparm2 = (OFXDouble2DParameter)fxo.FindParameterByName("Location");
            OFXDouble2D Pos;
            Pos.X = myX;
            Pos.Y = myY;
            tparm2.Value = Pos;

 

Thank you very much!!! :)

How do I know which parameters go into FindParameterByName()? For example, "Text", "Alignment", "Location" ... etc.

Thanks for continuing to help.

I have one more question.
How to set multiline text?
I did the following, but it does not work.
rtfText.Multiline = true;
rtfText.Text = "1 line \\r\\n 2th line \\r\\n 3rd line";

Thanks in advance.

jetdv wrote on 12/10/2020, 3:11 PM

There's at least three different ways to do that. First of all, your method *is* one of them but you need to remove a \ in each case so you get:

rtfText.Text = "1st line \r\n 2nd line \r\n 3rd line";

Alternately, you could:

rtfText.Text = "1st line" + System.Environment.NewLine + "2nd line" + System.Environment.NewLine + "3rd line";

Another option is:
 

rtfText.Text = "1st line";

rtfText.AppendLine("2nd line");

rtfText.AppendLine("3rd line");

As for additional parameters, you can actually iterate through all available OFX plugin parameters so you can just write them all out to a file. Or look in the development environment and you should be able to look at the various available parameters there as well. This should get you started:
 

                Effect gEffect = take.Media.Generator;

                ofx = effect.OFXEffect;

            foreach (OFXParameter ofxparm in ofx.Parameters)
            {
                MessageBox.Show("Name: " + ofxparm.Name + "  Label: " + ofxparm.Label + "   Type: " + ofxparm.ParameterType.ToString());
            }