7 Replies Latest reply on Sep 19, 2017 11:21 AM by John Messinger

    Processbook screen replication using C#

    Shreyamshu

      Hi,

           Is there any way to replicate numerous PDIs using C# codes only.(No VBA scripting)

       

      Thanks,

      Shreyamshu

        • Re: Processbook screen replication using C#
          John Messinger

          Hi Shreyamshu,

           

          What exactly do you mean by replicating these display files? You can manipulate ProcessBook objects from C# by referencing the appropriate interop assemblies found in %PIHOME%\Procbook\PublicAssemblies. If you can provide some more detail around what you are trying to accomplish we can help with a more detailed answer.

           

          Regards,

          John

          1 of 1 people found this helpful
            • Re: Processbook screen replication using C#
              Shreyamshu

              Hi John,

                   What I meant is suppose I have a processbook template already developed., and just need to make the same in multiple numbers(copying) , doing it manually is one thing. But I need the same to be done via coding. Could you help me with this.?

               

              Reagrds,

              Shreyamshu BK

                • Re: Processbook screen replication using C#
                  John Messinger

                  Hi Shreyamshu,

                   

                  A template implies that you want to make changes to the contents (such as the PI tags or AF objects being referenced) when making your copies, rather than just making straight out copies with no modification. Is this what you are intending to do? If this is the case, then you can still do this using C# and access the ProcessBook object model via the provided interop assemblies. What kind of specific changes are looking to make in these copies? If you are making no changes at all, then it becomes a simple file IO operation to duplicate a file n times. But I suspect this is not the case.

                   

                  The other question I have, is how familiar are you with the ProcessBook programming object model in VBA? If you are familiar with it, then once you have references to the display object and it's collection of symbols in your C# project, there isn't a whole lot of difference between VBA and C# when manipulating the symbols or the display.

                   

                  Here's a simple example of some code to manipulate a display in C#:

                   

                  PBObjLib.Application m_app = new PBObjLib.Application();
                  PBObjLib.Display display = m_app.Displays.Open(@"C:\Temp\Display1.PDI", 1);
                  m_app.RunMode = false;
                  PBObjLib.Symbols symbols = display.Symbols;
                  PBSymLib.Trend trend = (PBSymLib.Trend)symbols.Item("Trend1");
                  trend.AddTrace("Sinusoid");
                  display.Save();
                  

                   

                  You can find other examples in the forums - try searching for ProcessBook C#

                   

                  Regards,

                  John

                    • Re: Processbook screen replication using C#
                      Shreyamshu

                      Thank you so much John. And yes, just replication is not the motto here. Changes, as you mentioned, tag replacing, addition of a symbol (if necessary) etc.. are to considered too. And could you exactly tell me the difference between creating a pdi via c# and VBA.?

                       

                      Regards

                      Shreyamshu BK

                        • Re: Processbook screen replication using C#
                          John Messinger

                          There's not really a lot of difference. You would use the same objects and methods in both languages to create a new display and to manipulate it programmatically. The key difference is in ProcessBook VBA you don't need to explicitly reference any other libraries - in C# you will need to add references to the interop assemblies located in a sub-folder of the ProcessBook installation directory. As you would be working with COM, you will also need to handle the cleanup of your unmanaged resources.

                           

                          John

                  • Re: Processbook screen replication using C#
                    Santo

                    You would probably also want to make some changes in these "copies", that you are making. You are better off using VBA script to do this as it is very easy to manipulate the symbols and multistates and values from within processbook(VBA script). If you are stuck with C# you might have to deal with interop assemblies.

                      • Re: Processbook screen replication using C#
                        Shreyamshu

                        Thank you Santosh. I get your point. From what I understand, VBA is display specific whereas C# isn't. I've managed to come up few VBA scripts of my own. But when it comes to implementation C# seems to have wide scope through which not just the pdi's but also a lot of things can be done and I do not mind dealing with interop assemblies. Hence this approach.

                         

                        Regards,

                        Shreyamshu BK