2 Replies Latest reply on Jul 5, 2012 9:05 AM by Steve_Clay

    Dynamically creating PDI files from C# code


      Hello all,


      I have a C# console app which opens up an empty display file in ProcessBook, adds some text to it and saves the new pdi file.  This small proof of concept app works fine.  The PDI file that gets produced is just what I expected to see.  However, when I close the ProcessBook application from the C# code I get the following error message:




      Example Code shown below.  It is the last statement (line 48) "app.Close();" that causes the above error.  Any insight / help would be greatly appreciated. 

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Drawing;
      using System.Runtime.InteropServices;
      using PBObjLib;
      using PBSymLib;
      namespace Generate_ProcessBook_Pages
          class Program
              static void Main(string[] args)
                  PBObjLib.Application app = new PBObjLib.Application();
                  PBObjLib.Display disp = app.Displays.Open(@"C:\Temp\PDI\POC\Temp.PDI", false);
                  PBSymLib.Text pbText = (PBSymLib.Text)disp.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolText, System.Reflection.Missing.Value);
                  pbText.Name = "lblText";
                  pbText.Contents = "Dynamically added text";
                  //  Set background colour to "none"
                  pbText.BackgroundColor = -1;
                  PBSymLib.IDualFont pbFont = pbText.Font;
                  pbFont.Name = "Arial";
                  pbFont.Size = 16;
                  pbFont.Bold = false;
                  pbFont.Italic = false;
                  pbFont.Underline = false;
                  pbText.LineColor = ColorTranslator.ToOle(ColorTranslator.FromHtml("#000000"));
                  pbText.EnableScript = true;
                  pbText.Left = 10 - 15000;
                  pbText.Top = 15000 - 10;
                  pbText.Selected = false;
                  //Tidy up;
                  pbFont = null;
                  pbText = null;
                  string fileName = @"C:\Temp\PDI\POC\saved_file.pdi";
                  disp.SaveAs(fileName, PBObjLib.pbpdFILEFORMAT.pbpdFormatDisplay);
        • Re: Dynamically creating PDI files from C# code

          @Stephen: If you perform the same steps than in your code but manually, do you get the same error when you try leave PI ProcessBook? What version of PI ProcessBook are you using?


          I successfully test your code without any problem with PI ProcessBook version 2012. Which version of the PI SDK do you use?

            • Re: Dynamically creating PDI files from C# code

              Hi Mathieu,


              The problem did not occur when I manually performed the steps, only when using the above code.


              I read your post regarding the program versions and I realised I was not using the latest versions, never even occurred to me.  Argh! schoolboy error (I could kick myself).


              Anyway I've upgraded to ProcessBook 2012 this morning and the code works fine now.


              Thank you very much for taking the time to look into this.