3 Replies Latest reply on Jan 23, 2018 3:24 PM by kduffy

    Scripting in PI


      Hello All, I am new to vbscript. I want to give multistate to rectangle in processbook by scripting.How can we define rectangle name in vb script?

        • Re: Scripting in PI

          Hi Joshi,


          All static symbols (lines, rectangles, circles, polygons, etc) are not scriptable by default. Once you've added one to the display, you'll need to go into build mode, right click on the symbol, and select "Enable Scripting".


          At that point, the rectangle should be scriptable, and its name in the VBA context will be the same as in the display when you hover over the symbol in build mode:


          Lastly, is there a specific need for VBA for these symbols? Rectangles can become multistate symbols by clicking on them then on the multistate button, and the configuration menu there is usually everything you'd need. What specific actions were you looking to do within VBA?



          2 of 2 people found this helpful
            • Re: Scripting in PI

              Thank you Kelsey for your reply, Actually I have lots of  rectangles in my displays and each rectangles have multi state. I understood your point.We can give multi state to all the rectangles by clicking on the multi state symbol as shown in above image.But It becomes the tedious process.So I was thinking that Is there any alternative way of it or not. Can we give multi state to all the rectangles by writing vb script?  

                • Re: Scripting in PI

                  Hi Joshi,


                  Here is example code that you could employ to create the multi-state, although you'll still need to follow the above steps to enable scripting on the rectangles. You should be able to do that quickly by going into build mode, ctrl+a, right click on something, "enable scripting".


                  Then you can use code such as this to define the states:

                  Dim mymultistate As MultiState
                  Dim tagname As String
                  tagname = "sinusoid"
                  Set mymultistate = Rectangle1.CreateMultiState(tagname)
                  With mymultistate
                      .StateCount = 2
                      .DefineState 1, 0, 50
                      .DefineState 2, 50, 100
                  End With


                  It will follow the default color sequence controllable from ProcessBook > Tools > Preferences > Display Window > Color Palette.


                  To pull the existing multistate information from one rectangle and add it to another, you can do something like this:

                  Dim existingMSConfig As MultiState
                  Set existingMSConfig = Rectangle1.GetMultiState
                  Call Rectangle3.SetMultiState(existingMSConfig)



                  For any of these approaches, you can add this code to trigger on a button or similar, then disable it since you'll only want it to run once.



                  1 of 1 people found this helpful