5 Replies Latest reply on Mar 18, 2011 5:46 PM by Ahmad Fattahi

    Zero axis on ProcBook trend

    cjrancur

      I wanted to highlight the horizontal axis at value = 0 in red, for a ProcBook trend that includes data scaled equally in the positive and negative directions, like +5 to -5, for example.

       

      I thought I could use a dataset to build the equivalent of a PI tag that was always at zero, and then trend that dataset value with a red pen. 

       

       So I tried manually building a dataset, with the expression of sin(0), and it worked.  I have several ProcBooks that I'd like to configure this way, so I tried to automate the dataset creation in vba. 

       

      Now I'm stumped on an enumerator type.  I can't find the reference that includes "pbcDatasetExpression", and so my test won't compile.  Here's the code.  It is from the Process Book VBA Reference help file, except the expression uses sin(0) instead of sinusoid.

       
      Private Function makeDataSetForZeroAxis() As Dataset
      
      Dim Application As Object
      Dim MyDatasets As New Datasets
      Dim myDataSet As Dataset
      
          Set MyDatasets = Application.Datasets
          Set myDataSet = MyDatasets.Add("ZERO DEVIATION", Null, True, 1, True, pbcdatasetexpression)
          myDataSet.Expression = "'SIN(0)'"
          myDataSet.RefreshInterval = 3600
        
      End Function
      

       The help file also mentions a whitepaper on the support site, called "Creating a custom dataset", but I searched and could not find it.

       

       The above function fails to compile when it reaches the symbol, "pbcDatasetExpression", in the MyDatasets.Add method. I've tried adding the SDK common and SDK 1.3, plus pipc32 libraries, but I haven't found the right type for the "pbcDatasetExpression".  Then, I tried substituting pbcDatasetExpression with the number 0, and all I found was that vba does not know what "Application.Datasets" are, so I know I have other problems besides lacking the enumerator. 

       

       Maybe there's a better way to make the zero axis bold and red in ProcBook. Suggestions on doing this more simply are requested.

       

      If the dataset idea is the only way to do this, then please help me to find the necessary type libraries for the pbcdatasetexpression, and also please help with defining MyDatasets, because the above function gets a value of "nothing" for MyDatasets.

       

      Carrie

        • Re: Zero axis on ProcBook trend

          Hi Carrie,

           

          You need to change your code to:

           

           

           
          Call ThisDisplay.Datasets.Add("ZERO DEVIATION", Nothing, True, 1, True, pbDatasetPIExpression)
          
          Dim myDataSet As PIExpressionDataset
          Set myDataSet = ThisDisplay.Datasets.GetDataset("ZERO DEVIATION")
              myDataSet.ServerName = "servername"
              myDataSet.Expression = "0"
              myDataSet.RefreshInterval = 3600
              myDataSet.Interval = "10m"
          
          ThisDisplay.Datasets.SetDataset myDataSet
          

           

           

          You first add the new dataset (using the pbDatasetPIExpression value from the pbDatasetType enum) to the Datasets collection of the display and use the "GetDataset" function so you can modify the properties of the Dataset.  Then store the Dataset back to the Display's Datasets collection using "SetDataset".

           

          Hope this helps.

           

          In fact, you could even bundle this up in to a routine to parse multiple displays - e.g.

           

           

           
          Sub Test()
              Call makeDataSetForZeroAxis(Application.Displays(1))
              Call makeDataSetForZeroAxis(Application.Displays(2))
              Call makeDataSetForZeroAxis(Application.Displays(3))
              Call makeDataSetForZeroAxis(Application.Displays(4))
          End Sub
          
          Private Sub makeDataSetForZeroAxis(ByVal TheDisplay As Display)
           
          Const sZeroOffsetName As String = "ZERO DEVIATION"
           
          Dim ds As Dataset
          For Each ds In TheDisplay.Datasets
              If UCase(ds.Name) = sZeroOffsetName Then Exit Sub
          Next ds
           
          Call TheDisplay.Datasets.Add(sZeroOffsetName, Nothing, True, 1, True, pbDatasetPIExpression)
          
          Dim myDataSet As PIExpressionDataset
          Set myDataSet = TheDisplay.Datasets.GetDataset(sZeroOffsetName)
              myDataSet.ServerName = "WINXPSP201"
              myDataSet.Expression = "0"
              myDataSet.RefreshInterval = 3600
              myDataSet.Interval = "10m"
          
          TheDisplay.Datasets.SetDataset myDataSet
             
          End Sub
          

           

           

           

           

           

           

           

            • Re: Zero axis on ProcBook trend
              cjrancur

              There are lots of good things here, like setting a PI expression to a constant by just enclosing the constant as if it were a string.  If I wanted a constant,non-zero dataset, I might have tried abs(3) or 3*cos(0).  I was trying to do it the hard way.  I'm sure this is a better way.

               

              And I notice that the enumeration is pbDataSetPIExpression in your example, not pbcDatasetExpression, as demonstrated in the help files under "DataSet>DataSet Examples>Creating a Calculation Dataset".  

               

              I'd like to suggest that the help files be edited.  The example code probably worked well with older PB versions, but it does not seem to be correct now.  Should I submit a request to techsupport to get this done?

               

              Thank you, Rhys, I'll try this sample soon.

               

              Carrie