12 Replies Latest reply on Aug 1, 2017 1:05 PM by dhollebeek

    Using Visual Studio C# to programm ProcessBook

    Yuri_Kozyaev

      Hi,

       

        ProcessBook has built-in VBA. I can load pre-made display from Visual Studio using C#. Are any samples

      how to add new elements to ProcessBook-display from Visual Studio and programm them not using VBA?

       

      Thank you, Yuri

       

        • Re: Using Visual Studio C# to programm ProcessBook

          Hi Yuri,

           

          Do you have a vCampus subscription?  vCampus is our developer community and includes lots of great information on such topics:

           

          http://vcampus.osisoft.com/default.aspx

           

          There is a webinar there regarding just this topic and how to implement C# and VB.NET add-ins to ProcessBook

           

          http://vcampus.osisoft.com/auditorium/m/webinars/579.aspx

           

          In vCampus under the Download Center > Extras > you can get templates for implementing these ProcessBook add-ins.  They will allow you to create functions for manipulating your ProcessBook displays using C# in Visual Studios

          • Re: Using Visual Studio C# to programm ProcessBook
            Yuri_Kozyaev

            Thank for you answer,

             

               but video talks about programming Add-Ins to ProcessBook, not about programming Display itself.

             

            • Re: Using Visual Studio C# to programm ProcessBook
              cramsey

              hello Yuri-

               

              I assume you are loading displays using ActiveView, is that correct? If not, how?

               

               

              -clint

              • Re: Using Visual Studio C# to programm ProcessBook
                Yuri_Kozyaev

                I have found sample and tried it in VS C#. It works:

                 

                            PBObjLib.Application app = new PBObjLib.Application();
                            PBObjLib.Display disp = app.Displays.Open("C:\\Selection Pane V0.2.PDI", false);
                            PBObjLib.Symbol sym = disp.Symbols.Item(1);
                 
                Next question how to reach elements from disp?
                • Re: Using Visual Studio C# to programm ProcessBook
                  Yuri_Kozyaev

                  Simple example how to reach element "button" in ProcessBook Dispaly with just one ControlButton could be very helpful

                  • Re: Using Visual Studio C# to programm ProcessBook
                    Lonnie Bowling
                    
                    var App = new PBObjLib.Application();
                    PBObjLib.Display pdi = App.Displays.Open(displayFileName, 1);
                    
                    PBObjLib.Symbols collSym = pdi.Symbols;
                    
                    foreach (PBObjLib.Symbol selectedSym in collSym)
                    {
                       if (selectedSym is PBSymLib.Value)
                       {
                           var sValue = (PBSymLib.Value)selectedSym;
                           //do something with the value...
                       }else if (selectedSym.IsMultiState)
                       {
                          var sMS = (PBObjLib.MultiState)selectedSym.GetMultiState();
                          //do something with the multiState
                       }
                    }
                    
                    

                    Here is a example of how to get various elements from a pdi file using C#.

                     

                    Good luck!

                     

                    Lonnie

                      • Re: Using Visual Studio C# to programm ProcessBook
                        Shreyamshu

                        Hello Lonnie, I am new to using ProcessBook via C# dot net. I've used the above mentioned code as it is in my Console Application and upon running the application I get the following error "System.Runtime.InteropServices.COMException was unhandled   ErrorCode=-2147467259   HResult=-2147467259   Message=Error HRESULT E_FAIL has been returned from a call to a COM component.". How can I make it work.? And I am trying to open an already existing Processbook screen.!

                          • Re: Using Visual Studio C# to programm ProcessBook
                            John Messinger

                            Can you post the code you are executing? That would be helpful to know what is potentially happening in your program.

                             

                            Given that Lonnie's code is just an example and doesn't include error handling, I would assume that your code does include proper error handling to catch COMExceptions, which are the main Exception type that will be thrown when interacting with ProcessBook via .NET.

                            1 of 1 people found this helpful
                              • Re: Using Visual Studio C# to programm ProcessBook
                                Shreyamshu

                                var app = new PBObjLib.Application();

                                            PBObjLib.Display pdi = app.Displays.Open("D:\\Shreyamshu\\ADCO\\BAB\\Old_A2 SCADA\\Unique Screens\\BAB Symbol Library.pdi", 1);

                                 

                                 

                                            PBObjLib.Symbols collsym = pdi.Symbols;

                                 

                                 

                                            foreach (PBObjLib.Symbol selectedSym in collsym)

                                            {

                                                if (selectedSym is PBSymLib.Value)

                                                {

                                                    var sVal = (PBSymLib.Value)selectedSym;

                                                    Console.WriteLine(" Value is : " + sVal);

                                                }               

                                            }

                                 

                                 

                                            Console.WriteLine(" Screen opened successfully.");  //Just to check whether the screen is opened or not.!

                                            Console.ReadLine();

                                 

                                Could you help me with how I can acutally draw an object in processbook using visual studio.

                                  • Re: Using Visual Studio C# to programm ProcessBook
                                    dhollebeek

                                    First of all, I would either step through the code in the debugger to see which line the error is throw on, or configure the debugger to break if a COM error is thrown.  I'll take a guess though and I think the error is in the "Value is" line.  sVar is a PBSymLib.Value.  That means it is a COM object to interface with the entire PB value symbol, not a string value.  In order to get the actual value being displayed, you need to call sVal.GetValue().

                                     

                                    If by "drawing an object using Visual Studio" you mean creating a custom symbol that you can place on a display, there is no good way to do that.  You could can create Active-X controls to do that's a very old technology, so I wouldn't recommend using it.  It could literally take you years just to learn how to implement Active-X in managed code.

                                     

                                    If you want to display information inside of ProcessBook, the best way is to create an add-in that shows a docking window (similar to what Details and ERD do).  I think if you search the tech support site, there are examples of how to create an add-in.

                                     

                                     

                                    • Re: Using Visual Studio C# to programm ProcessBook
                                      John Messinger

                                      To draw a new symbol, you want to use the Symbols.Add method. Here's a simple example of this to draw a Trend symbol:

                                       

                                      try
                                      {
                                      var App = new PBObjLib.Application();
                                      PBObjLib.Display pdi = App.Displays.Add("Symbol Automation");
                                      
                                      
                                      var trend = pdi.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolTrend) as PBSymLib.Trend;
                                      trend.AddTrace("sinusoid");
                                      trend.SetStartAndEndTime("*-12h", "*");
                                      
                                      
                                      pdi.Save();
                                      }
                                      catch (COMException e)
                                      {
                                      Console.WriteLine(e.ToString());
                                      }
                                      

                                       

                                      The ProcessBook Programmer reference Guide (found in C:\Program Files (x86)\PIPC\help\en\Pipbvb.chm) will give you more information on the specifics of manipulating various symbols programatically.

                                      2 of 2 people found this helpful