Script to Fade In/out not working

melliott1963 wrote on 8/25/2016, 9:11 AM

I'm trying to get Edward Troxel's script working in Magix Vegas 13 Pro, build 543, but without any success.

The script is:-

/**
* This script will Fade the selected audio track up to the current cursor position
*
* Written By: Edward Troxel
* Modified: 04-21-2003
**/

import System;
import System.IO;
import System.Windows.Forms;
import Sony.Vegas;


try {


//Go through the list of Tracks
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());

//Go through the list of Events
var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd()) {
var evnt : TrackEvent = TrackEvent(eventEnum.item());

if (evnt.Selected) {

evnt.FadeIn.Length = new Timecode("00:00:01:00");
evnt.FadeOut.Length = new Timecode("00:00:01:00");

}
eventEnum.moveNext();
}
trackEnum.moveNext();
}


} catch (e) {
MessageBox.Show(e);

If I run it as a .js file, I get the following error:-

D:\Vegas\Scripts\FadeInOut1Second.js(42) : Expecting more source characters

and if I change the extension to .cs, I get these errors:-

D:\Vegas\Scripts\FadeInOut1Second.cs(9) : A namespace cannot directly contain members such as fields or methods
D:\Vegas\Scripts\FadeInOut1Second.cs(19) : Expected class, delegate, enum, interface, or struct
D:\Vegas\Scripts\FadeInOut1Second.cs(24) : Expected class, delegate, enum, interface, or struct
D:\Vegas\Scripts\FadeInOut1Second.cs(30) : Expected class, delegate, enum, interface, or struct
D:\Vegas\Scripts\FadeInOut1Second.cs(31) : Expected class, delegate, enum, interface, or struct
D:\Vegas\Scripts\FadeInOut1Second.cs(33) : Type or namespace definition, or end-of-file expected

And ideas how I can get it to work?

Thank you.

 

Comments

Gary James wrote on 8/25/2016, 9:40 AM

Where is your script entry point with the FromVegas function call?

melliott1963 wrote on 8/25/2016, 9:45 AM

Sorry, but that means nothing to me! :)

I have 2 files, one with a js extension, and the other with a cs extension, and all I am doing is using the Run Script command in Vegas and chosing one of these files

NickHope wrote on 8/25/2016, 10:23 AM

I think you're just missing a closing squiggly bracket. Just add a } at the end.

Gary James wrote on 8/25/2016, 10:49 AM

Ok, never mind.  I made the assumption that you were creatnig a compiled script, not a stand alone text script.  Every script or extension I've ever made has been compiled into a dll; so it's in my nature to think that way first.

melliott1963 wrote on 8/25/2016, 11:27 AM

Nick - Sorry, I just missed that off of my copy and paste, it is in the script.

NickHope wrote on 8/25/2016, 12:51 PM

I suppose the scripting namespace change might have already been integrated into build 543. Unlikely, as I think MAGIX would have specifically told us, but possible. You could try making the changes described in this post and see.

NickHope wrote on 8/25/2016, 12:52 PM

By the way your script is working correctly here in V13 build 453 if I add the final bracket.

melliott1963 wrote on 8/25/2016, 2:21 PM

I did have a script working, but then had to rebuild my laptop. As part of the rebuild I installed the latest version, and unfortunately hadn't backed up my original script. I guess it could be something with the new version. Would be interested to know if anyone has got it working and if so, could it be that I'm missing something from my install?

By the way, have you saved it as a .js or .cs file? 

jetdv wrote on 8/25/2016, 10:26 PM

It is a .js script. Based on the error message, you're missing part of the script or have something entered after the closing bracket. The error is on line 42 so look on that line. Also realize the script was written in 2003 for Vegas Pro 4 and I would certainly do it differently today (with the same net results).

 

NickHope wrote on 8/26/2016, 2:17 AM

I'm guessing the new namespace change has already happened in MAGIX Vegas 13 build 543 [Edit: It hasn't!], so this should be correctly modified to work in it, but I haven't tested it as I'm staying with the older build until V14 arrives:

/**
* This script will Fade the selected audio track up to the current cursor position
*
* Written By: Edward Troxel
* Modified: 04-21-2003
* 08-26-2016 - Modified for MAGIX Vegas Pro versions by Nick Hope
**/

import System;
import System.IO;
import System.Windows.Forms;
import ScriptPortal.Vegas;

try {

//Go through the list of Tracks
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());

//Go through the list of Events
var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd()) {
var evnt : TrackEvent = TrackEvent(eventEnum.item());

if (evnt.Selected) {

evnt.FadeIn.Length = new Timecode("00:00:01:00");
evnt.FadeOut.Length = new Timecode("00:00:01:00");

}
eventEnum.moveNext();
}
trackEnum.moveNext();
}

} catch (e) {
MessageBox.Show(e);
}

I've uploaded the modified version here (open in browser then save page as a .js file). I hope you don't mind, Edward.

melliott1963 wrote on 8/26/2016, 2:51 AM

I think it's nearly there! it now needs 3 of the variable declared:

D:\Vegas\Scripts\FadeInOut1Second.js(19) : Variable 'Track' has not been declared
D:\Vegas\Scripts\FadeInOut1Second.js(24) : Variable 'TrackEvent' has not been declared
D:\Vegas\Scripts\FadeInOut1Second.js(28) : Variable 'Timecode' has not been declared

 

NickHope wrote on 8/26/2016, 3:31 AM

What happens if you run this .js script? You can download it at https://dl.dropboxusercontent.com/u/21489814/test.js It should tell you the Vegas version number, if the namespace in version 543 has been changed from Sony.Vegas to ScriptPortal.Vegas and scripting functionality is otherwise unchanged.

import System.Windows.Forms;
import ScriptPortal.Vegas;

MessageBox.Show("Vegas.Version: " + Vegas.Version);
melliott1963 wrote on 8/26/2016, 3:41 AM

I get the following:-

Vegas.Version: Version 13.0 (Build 543) 64-bit

NickHope wrote on 8/26/2016, 4:02 AM

Right, so that confirms that the namespace change has been implemented in version 543 and is correct [Edit: It doesn't!]. I'm afraid I can't help beyond that without hours of work, as I'm not programmer. I have further weirdness here in that the original script only works in my V12 and not in my V13 (version 453), but it fails without an error message in V13. Vegasaur can do this in its "Quick Properties > Fades / Transitions" section, and possibly other multi-function plugins too. Or perhaps someone who knows what they are doing can write an updated script.

rs170a wrote on 8/26/2016, 4:24 AM

Here's the official from Gary Rebholz in the Namespace change coming for Vegas Pro 14 thread. I hope it helps 😊

 

The scripting namespace for VEGAS Pro 14 changes from “Sony” to “ScriptPortal”. In your scripts, any occurrence of items like “Sony.Vegas” or “Sony.MediaSoftware” must be changed to “ScriptPortal.Vegas” and “ScriptPortal.MediaSoftware”. We chose this namespace (“ScriptPortal”) in order to remove any company branding and thus avoid this problem in the future.

For stand-alone scripts (not a compiled extension), you can easily make this change yourself even without any programming knowledge. Open the script with Notepad (always work on a copy of the script in case you make a mistake) and replace “Sony” with “ScriptPortal”. Save the script with a new filename so that you still have a copy that works in pre-14 versions of VEGAS Pro.

melliott1963 wrote on 8/26/2016, 12:45 PM

No, sorry rs170a, this is what we've done in the script and it's still not working.

It's not the end of the world as I will just have to manually add my fade ins and outs and I always used to before using the scripts.

Hopefully someone with some programming knowledge will come up with a fix eventually.

Former user wrote on 8/26/2016, 1:05 PM

Nick, I am not a programmer but looking at your script it looks like you are missing a { somewhere. Just counting open and closes and there is one more close than there is an open. I may be wrong, so forgive me my ignorance.

paul_w wrote on 8/26/2016, 1:22 PM

Right, so that confirms that the namespace change has been implemented in version 543 and is correct.

Interesting. Developers with v13 - 543 can start testing script changes ahead of a v14 release?

melliott1963 wrote on 8/26/2016, 1:46 PM

Sorry, but I've looked and as far as I can see (unless I'm missing something obvious) there are the same number of open and close squirly brackets - 5 of each. I've counted them below.....

/**
* This script will Fade the selected audio track up to the current cursor position
*
* Written By: Edward Troxel
* Modified: 04-21-2003
* 08-26-2016 - Modified for MAGIX Vegas Pro versions by Nick Hope
**/

import System;
import System.IO;
import System.Windows.Forms;
import ScriptPortal.Vegas;

try { *1o*

//Go through the list of Tracks
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) { *2o*
var track : Track = Track(trackEnum.item());

//Go through the list of Events
var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd()) { *3o*
var evnt : TrackEvent = TrackEvent(eventEnum.item());

if (evnt.Selected) { *4o*

evnt.FadeIn.Length = new Timecode("00:00:01:00");
evnt.FadeOut.Length = new Timecode("00:00:01:00");

} *1c*
eventEnum.moveNext();
} *2c*
trackEnum.moveNext();
} *3c*

} *4c* catch (e) { *5o*
MessageBox.Show(e);
} *5c*

Former user wrote on 8/26/2016, 1:49 PM

Yeah, my bad. Sorry

jetdv wrote on 8/26/2016, 7:52 PM

Ok, I've converted it to .cs and changed the namespace. Please try this version (save it as FadeInOut1Second.cs)

 

/**
 * This script will add a one second Fade In and out to all selected events.
 *
 * Written By: Edward Troxel
 * Copyright 2016 - JETDV Scripts
 * Modified: 08-26-2016
 * Converted to .CS and new Vegas namespace
 **/

 

using System;
using ScriptPortal.Vegas;

 


public class EntryPoint
{
  Vegas myVegas;

 

  public void FromVegas(Vegas vegas)
  {
    myVegas = vegas;

 

    foreach (Track track in myVegas.Project.Tracks)
    {
        foreach (TrackEvent trackEvent in track.Events)
        {
            if (trackEvent.Selected)
            {
                trackEvent.FadeIn.Length = new Timecode(1000);
                trackEvent.FadeOut.Length = new Timecode(1000);
            }
        }
    }
  }
}

melliott1963 wrote on 8/27/2016, 2:37 AM

New errors now:-

D:\Vegas\Scripts\FadeInOut1Second.cs(13) : The type or namespace name 'ScriptPortal' could not be found (are you missing a using directive or an assembly reference?)
D:\Vegas\Scripts\FadeInOut1Second.cs(20) : The type or namespace name 'Vegas' could not be found (are you missing a using directive or an assembly reference?)
D:\Vegas\Scripts\FadeInOut1Second.cs(24) : The type or namespace name 'Vegas' could not be found (are you missing a using directive or an assembly reference?)
 

melliott1963 wrote on 8/27/2016, 2:39 AM

All fixed!

I thought that, just out of interest, I'd change ScriptPortal back to Sony, and its working fine.

Thank you everyone for your help.

NickHope wrote on 8/27/2016, 3:01 AM

So the conclusion is that in MAGIX Vegas version 543, .js scripts need the new namespace but .cs scripts need the old namespace [Edit: It isn't!]. Some clarification from MAGIX would be welcome here.