6 Replies Latest reply on Apr 13, 2011 3:05 PM by wpurrer

    automatically generated "pdi - Files" in Csharp

    wpurrer

      * I need to migrate a couple of old user interfaces to processbook.
      * from the old system i have the tags per screen
      * how do i create in .net / c#  screen

       


      The following gives me the error message:

       

      System.Runtime.InteropServices.COMException was unhandled
        HelpLink=""
        Message=The called method is not supported in embedded mode.
        Source=PI ProcessBook
        ErrorCode=-2147213170
        StackTrace:
             bei PBObjLib.DisplayClass.SaveAs(String szFileName, pbpdFILEFORMAT vFileFormat)
             bei ConsoleApplication1.Program.Main(String[] args)
             bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
             bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
             bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
             bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
             bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
             bei System.Threading.ThreadHelper.ThreadStart()
        InnerException:

       

      =====

       

      PBObjLib.Application ap = new PBObjLib.Application();
      PBObjLib.
      Display d = new PBObjLib.DisplayClass();
      d.SaveAs(
      "test.pdi");

        • Re: automatically generated "pdi - Files" in Csharp
          wpurrer

          I forgot to write in a console application

            • Re: automatically generated "pdi - Files" in Csharp

              PBObjLib.Application ap = new PBObjLib.Application();

               

              PBObjLib.Display d = ap.Displays.Add("test");

               

              d.SaveAs("test.pdi");

               

              ?

                • Re: automatically generated "pdi - Files" in Csharp
                  wpurrer

                  Sorry, thank you that was to easy, what is also funny, that the "sym.width=1024 and settimerange isn'T recognized" => it is still a very small trend

                   
                  using System.Collections.Generic;
                  using System.Text;
                  using PBSymLib;
                  using PBObjLib;
                  
                  namespace ConsoleApplication2
                  {
                      class Program
                      {
                          static void Main(string[] args)
                          {
                              
                              
                              System.IO.TextReader tr = new System.IO.StreamReader(@"test_ges.csv", Encoding.Default);
                  
                              string basispfad = @"test\";
                  
                              string lastid = "";
                              string lastfilename="";
                              string lastdir="";
                              PBObjLib.Display d = null;
                              PBObjLib.Application ap = new PBObjLib.Application();
                              Symbol sym = null;
                              tr.ReadLine();
                              while (true)
                              {
                                  string s = tr.ReadLine();
                  
                                  if (s == null)
                                      break;
                  
                                  string[] items = s.Split(';');
                  
                                  
                                  if (items.Length == 5)
                                  {
                                      string newid = items[0] + items[1];
                                      string abteilung = items[0];
                  
                                      int nr = Convert.ToInt16(items[1]);
                  
                                      string nicefilename =nr.ToString("0000") + "_" + items[2].Replace("@", " ").Replace("\\", " ").Replace("/", " ").Replace("*", " ").Replace("\"","");
                                       
                                      
                                      if (d != null)
                                      {
                                          if (newid != lastid)
                                          {
                                      
                                              if (!System.IO.Directory.Exists(basispfad+"\\"+abteilung))
                                                  System.IO.Directory.CreateDirectory(basispfad+"\\"+abteilung);
                                              
                                              d.SaveAs(basispfad + "\\" + lastdir + "\\" + lastfilename+".pdi");
                                              d.Close(false);
                                          }
                                      
                                      }
                  
                                      if (newid != lastid)
                                      {
                                          d = ap.Displays.Add(newid);
                                          d.SetTimeRange("*-7d", "*");
                                          sym = (Symbol)d.Symbols._xAdd(PBObjLib.pbSYMBOLTYPE.pbSymbolTrend);
                                          sym.Width = 1024;
                                          sym.Height = 768;                                               
                                      }
                  
                                      Trend t = (Trend)sym;
                                      try
                                      {
                                          t.AddTrace(@"\\server\prefix." + items[4]);
                                      }
                                      catch (System.Exception ex) { }
                                      t.SetTraceScale(0, 1000);
                                      
                  
                                      lastid = newid;
                                      lastdir = abteilung;
                                      lastfilename = nicefilename;
                                  }
                              
                              }
                  
                          }
                      }
                  }