3 Replies Latest reply on Jul 14, 2016 8:30 PM by ernstamort

    List of PIUnitBatches and Subbatches via vba

    ThomasMundt

      Hi, I am trying to generate a list of all PIUnitBatches and Subbatches via vba like the one I get with the Batch Group function in ProcessBook (see 2nd screenshot).

      This Batches and Subbatches were created with the PI Batch Generator and are not the result of the OSIsoft Batch Interface.

       

      I tried this code (1st screenshot), but it returns only PIBatches and not PIUnitBatches and Subbatches (highlighted green).

       

      Please, could anyone give me a hint?

      Thanks, Thomas

       

        • Re: List of PIUnitBatches and Subbatches via vba
          Dan Fishman

          That code does not print out the units batches or sub-batches but you can easily modify it.  You probably want to use a recursive function for the sub-batches.

           

           

           

          You could do the following:

          For Each Batch In BatchList
                  Debug.Print Batch
                  Set UnitBatchList = Batch.PIUnitBatches
                  For Each UnitBatch In UnitBatchList
                      Debug.Print UnitBatch
                      Set subBatches = UnitBatch.PISubBatches
                      For Each SubB In subBatches
                          Debug.Print SubB
                      Next SubB
                  Next UnitBatch
              Next Batch
          
          1 of 1 people found this helpful
            • Re: List of PIUnitBatches and Subbatches via vba
              ThomasMundt

              Hi Dan, thanks for your answer.

               

              The function PIBatchSearch seems to return only "real" Batches, not some generated by PIBaGen.

              It lasts a while but now I know I have to use PIUnitBatchSearch, but to do this first I need to know the correct Module / Submodule.

               

              It works fine:-)

               

                             ...searching for the correct module first,

                             ...then:

               

                           

                Set UbList = SubModule.PIUnitBatchSearch("*", "*-7d", "*", "*Product abc*", "*", "*")
                            
                              For Each UnitBatch In UbList
                                  Debug.Print UnitBatch.BatchID, UnitBatch.Product, UnitBatch.startTime.LocalDate, UnitBatch.endTime.LocalDate, UnitBatch.PIUnit
                            
                                  Set SubBatches = UnitBatch.PISubBatches
                                
                                  For Each SubBatch In SubBatches
                                       Debug.Print SubBatch.Name, SubBatch.startTime.LocalDate, SubBatch.endTime.LocalDate
                                  Next SubBatch
                            
                              Next
              
              1 of 1 people found this helpful