Subject:Please help -> ForgeApp.DoMenuAndWait(cmd,false);
Posted by: jpal20002001
Date:7/26/2010 3:25:58 PM
this script is used in SF8 Somebody, please help. for some reason, when i use the Do command, it prevents me from adding markers via script. Any ideas why? If i comment it out, then everything works fine. Here is the File that performs the Do command. Below this is the file that the Do command calls. Script 1: _________________________________________________ import System; import System.Windows.Forms; import SoundForge; //Run with one file open and the Region Lists visible (Menu: View, Regions List) //Sets markers at set intervals, creating names in this format: prefix+time+suffix //NOTE: Look for MODIFY HERE to quickly update the script with your own preferences //NOTE: Uses an undo wrapper, so that you can undo all markers in one step public class EntryPoint { public function Begin(app : IScriptableApp) { var wnd = app.ActiveWindow; if (null == wnd) { app.SetStatusText("Open a file before running this script."); return; } DPF("Reading Files..."); var strDir = "\\\\pmi-w63\\C$\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\pastors_perspective\\audio\\Categorized Questions from 2008 - 10 October"; if (readFiles(strDir) == 0) return; var FileIndex = new ActiveXObject("FileIndex.Start"); FileIndex.Initiate(); FileIndex.SetDir(strDir); var arrayLine = dirFiles[0].split("*"); var shortPath = arrayLine[0].split("/"); var shortPathCount : int = shortPath.length - 1; var strFileName = shortPath[shortPathCount]; var strQuestion = arrayLine[1]; DPF("FileName: "+strFileName); DPF("Question: "+strQuestion); FileIndex.CreateOpenFileTest(strFileName); Do("Script.OpenFileTest"); if (null == wnd) { app.SetStatusText("Open a file before running this script."); return; } //MODIFY HERE. var step : double = 12.3; //change from every 12.3 seconds to something else var szPre = "pre"; //first part of the marker name. Type "" to leave blank var szPost = "post"; //last part of the marker name. Type "" to leave blank var myfile : ISfFileHost = app.CurrentFile; var ccLength : Int64 = myfile.Length; var ccStep : Int64 = myfile.SecondsToPosition(12.3); // create an undo wrapper, so we don't end up with an undo for every marker that we create... // var szUndo = String.Format("Create Markers every {0:g} seconds", step); var idUndo : int = myfile.BeginUndo(szUndo); var mk : SfAudioMarker = new SfAudioMarker(ccStep); var name = String.Format("{0} {1:###.##} {2}", szPre, myfile.PositionToSeconds(ccStep), szPost); mk.Name = name.Trim(); myfile.Markers.Add(mk); // close the undo wrapper, and tell it to keep the changes. // myfile.EndUndo(idUndo, false); } public function readFiles(dirPath){ var txtFile = new ActiveXObject("sfReadFiles.Open"); var txtInfo = txtFile.DirFiles(dirPath); if (txtInfo == "") return 0; dirFiles = txtInfo.split("[files]"); return 1; } public function Do(cmd) { ForgeApp.DoMenuAndWait(cmd,false); } public function Do(cmd,fUseLastPreset) { ForgeApp.DoMenuAndWait(cmd,fUseLastPreset); } public function FromSoundForge(app : IScriptableApp) { ForgeApp = app; app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name)); Begin(app); app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name)); } public var ForgeApp : IScriptableApp = null; public var dirFiles; public function DPF(sz) { ForgeApp.OutputText(sz);} public function DPF(sz,o) { ForgeApp.OutputText(System.String.Format(sz,o)); } public function DPF(sz,o,o2) { ForgeApp.OutputText(System.String.Format(sz,o,o2)); } public function DPF(sz,o,o2,o3) { ForgeApp.OutputText(System.String.Format(sz,o,o2,o3)); } } // class EntryPoint This is the file that the Do command calls Script 2: _________________________________________________ using System; using System.IO; using System.Windows.Forms; using SoundForge; public class EntryPoint { public void Begin(IScriptableApp app) { ISfFileHost file = app.CurrentFile; //string szFilename = "C:\\2008 - 09 September - 7th Day Adventist - 01.mp3";//file.Filename; string szFilename = "\\\\pmi-w63\\C$\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\pastors_perspective\\audio\\Categorized Questions from 2008 - 10 October\\2008 - 10 (October) - General Questions - 01.mp3";//file.Filename; file.Close(CloseOptions.DiscardChanges); file = null; file = app.OpenFile(szFilename, false, false); if (file != null) { file.WaitForDoneOrCancel(); } ISfFileHost file2 = app.OpenFile(szFilename, false, false); } public void FromSoundForge(IScriptableApp app) { ForgeApp = app; //execution begins here app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name)); Begin(app); app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name)); } public static IScriptableApp ForgeApp = null; public static void DPF(string sz) { ForgeApp.OutputText(sz); } public static void DPF(string fmt, object o) { ForgeApp.OutputText(String.Format(fmt,o)); } public static void DPF(string fmt, object o, object o2) { ForgeApp.OutputText(String.Format(fmt,o,o2)); } public static void DPF(string fmt, object o, object o2, object o3) { ForgeApp.OutputText(String.Format(fmt,o,o2,o3)); } public static string GETARG(string k, string d) { string val = Script.Args.ValueOf(k); if (val == null || val.Length == 0) val = d; return val; } public static int GETARG(string k, int d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsInt(k); } public static bool GETARG(string k, bool d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsBool(k); } } //EntryPoint Message last edited on7/26/2010 3:27:24 PM byjpal20002001. |
Subject:RE: Please help -> ForgeApp.DoMenuAndWait(cmd,false);
Reply by: ExSonyTJ
Date:7/26/2010 10:25:09 PM
Um, yeah. That's not going to work. The script engine isn't recursive. A script can't run another script and then get control back when it's done. But there isn't any need for a script to run a script. Just put all of the the code into a single script and then run it. In your example, you should just call app.OpenFile from the original script rather than trying to do it indirectly by running another script. |
Subject:RE: Please help -> ForgeApp.DoMenuAndWait(cmd,false);
Reply by: jpal20002001
Date:7/27/2010 9:23:28 AM
Of course... i was being lazy from having to convert the syntax of c# to jscript, but now I got it. Being that I am not too familiar with the c# syntax, I was reluctant to doing. Nevertheless, thanks so much! Your info pushed me in the right direction. Thanks Again. Message last edited on7/27/2010 9:43:51 AM byjpal20002001. |