Click here to Skip to main content
15,887,175 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Object reference not set to an instance of an object Pin
LAPEC6-Feb-11 10:31
LAPEC6-Feb-11 10:31 
GeneralRe: C# Object reference not set to an instance of an object Pin
RobCroll7-Feb-11 2:12
RobCroll7-Feb-11 2:12 
GeneralRe: C# Object reference not set to an instance of an object Pin
Rob Philpott7-Feb-11 3:51
Rob Philpott7-Feb-11 3:51 
AnswerRe: C# Object reference not set to an instance of an object Pin
Luc Pattyn6-Feb-11 9:15
sitebuilderLuc Pattyn6-Feb-11 9:15 
AnswerRe: C# Object reference not set to an instance of an object Pin
dan!sh 6-Feb-11 10:07
professional dan!sh 6-Feb-11 10:07 
QuestionObtain the path and save the file. Pin
sososm6-Feb-11 2:45
sososm6-Feb-11 2:45 
AnswerRe: Obtain the path and save the file. Pin
OriginalGriff6-Feb-11 2:52
mveOriginalGriff6-Feb-11 2:52 
GeneralRe: Obtain the path and save the file. Pin
sososm6-Feb-11 5:39
sososm6-Feb-11 5:39 
I've succeeded to make the script render the file to a specified location keeping the original name and close without saving the opened one. I don't know how to get the fields from the xml file and set them to the output filename.
I know I must get the path of the .xml file then extract the needed fields from it but I don't know how to do it.
Here is the script I use:

using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;

public class EntryPoint {
public string Begin(IScriptableApp app) {

   string[] outputs = new string[] {
      ".wav|Default Template",
   };

   string szDir = GETARG("Dir", @"c:\");

   ISfFileHost file = app.CurrentFile;
   if (null == file)
      return "No files are open. Script canceled.";

   string szBase = file.Window.Title;

   DPF("Start Rendering... ");
   foreach (string output in outputs)
   {

      string[] fmt = output.Split(new char[]{'|',';'},2);

// find the renderer

      ISfRenderer rend = null;
      if (fmt[0].StartsWith("."))
          rend = app.FindRenderer(null, fmt[0]);
      else
          rend = app.FindRenderer(fmt[0], null);
      if (null == rend)
      {
         DPF("renderer for type {0} not found - skipping to next", fmt[0]);
         continue;
      }

      // determine if the preset is a string or an integer

      object vPreset = fmt[1];

      string szName = String.Format("{0}", szBase, fmt[1], rend.Extension);
      DPF("rendering {0}", szName);
      string szFilename = Path.Combine(szDir, szName);
      DPF(" ~ {0}", szFilename);

      // now, render the file
      //
      file.RenderAs(szFilename, rend.Guid, vPreset, null, RenderOptions.RenderOnly);
      SfStatus result = file.WaitForDoneOrCancel();
      if (result != SfStatus.Success)
         continue;

file.Close(CloseOptions.DiscardChanges);

   } // foreach

   return null;

}

public void FromSoundForge(IScriptableApp app) {
   ForgeApp = app; //execution begins here
   app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
   string msg = Begin(app);
   app.SetStatusText(msg != null ? msg : 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


Thank you.
AnswerRe: Obtain the path and save the file. Pin
Abhinav S6-Feb-11 6:10
Abhinav S6-Feb-11 6:10 
QuestionError: "Could not use"file name"; file already in use." [SOLVED] Pin
Marat Beiner5-Feb-11 22:26
Marat Beiner5-Feb-11 22:26 
AnswerRe: Error: "Could not use"file name"; file already in use." Pin
Elham M5-Feb-11 23:06
Elham M5-Feb-11 23:06 
AnswerRe: Error: "Could not use"file name"; file already in use." Pin
OriginalGriff5-Feb-11 23:10
mveOriginalGriff5-Feb-11 23:10 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
Marat Beiner5-Feb-11 23:18
Marat Beiner5-Feb-11 23:18 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
OriginalGriff5-Feb-11 23:24
mveOriginalGriff5-Feb-11 23:24 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
Marat Beiner5-Feb-11 23:30
Marat Beiner5-Feb-11 23:30 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
OriginalGriff5-Feb-11 23:32
mveOriginalGriff5-Feb-11 23:32 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
Marat Beiner5-Feb-11 23:37
Marat Beiner5-Feb-11 23:37 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
OriginalGriff5-Feb-11 23:42
mveOriginalGriff5-Feb-11 23:42 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
Marat Beiner5-Feb-11 23:57
Marat Beiner5-Feb-11 23:57 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
OriginalGriff6-Feb-11 0:24
mveOriginalGriff6-Feb-11 0:24 
AnswerRe: Error: "Could not use"file name"; file already in use." Pin
Eddy Vluggen6-Feb-11 1:09
professionalEddy Vluggen6-Feb-11 1:09 
AnswerRe: Error: "Could not use"file name"; file already in use." Pin
Henry Minute6-Feb-11 7:09
Henry Minute6-Feb-11 7:09 
AnswerRe: Error: "Could not use"file name"; file already in use." Pin
Marat Beiner6-Feb-11 7:22
Marat Beiner6-Feb-11 7:22 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
Henry Minute6-Feb-11 9:39
Henry Minute6-Feb-11 9:39 
QuestionUnity DI config implementation question Pin
Member 39190495-Feb-11 18:40
Member 39190495-Feb-11 18:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.