Is there a way to change the server referred to in a data set from VBA in PI ProcessBook?
I did get a loop to iterate through each of the data sets in a test ProcessBook display I created, maybe this will help.
Dim MyDisplay As Display
Dim MyDatasets As Datasets
Dim MyDataset As Dataset
Dim Count As Integer
Set MyDisplay = ThisDisplay
Set MyDatasets = MyDisplay.Datasets
Count = MyDatasets.Count
For Index = 1 To Count
Set MyDataset = MyDatasets.GetDataset(MyDatasets.Item(Index).Name)
MyDataset.Description = "Edited"
'Path = MyDataset.Parent.Path
They key for me was to get the data set object by name in line 11 so I could edit the properties of the set.
John Messinger's response in this previous PI Square post may prove helpful here:Problem creating a PIExpression dataset in Processbook 2015 Version 220.127.116.114.
Set myDataSets = ThisDisplay.Datasets
Set myDS = myDataSets.Add("Test", Nothing, True, 1, True, pbDatasetPIExpression)
Set myDS = myDataSets.GetDataset("Test")
.ServerName = "SOCC"
.Expression = myExp
' .Expression = "'sinusoid'*3"
.Description = "Edit at " & Now()
.ColumnName = "Value"
.RefreshInterval = 3600
.Interval = "10M"
I'm getting "Object doesn't support this property or method" errors when trying to use the "myDataSets.SetDataset". This is when attempting to edit it at the ProcessBook level. Are there certain conditions that need to be met?
Are you using GetDataset to get an editable copy of that data set as below?
Dim MyEditDataset as Dataset
‘ Use the Datasets.GetDataset to obtain an editable copy of the desired
Set MyEditDataset = ThisDisplay.Datasets.GetDataset("NewOne")
MyEditDataset.Visible = True
MyEditDataset.Description = "Modified Dataset"
MyEditDataset.Stepped = True
‘ The changes are not made permanent until the Datasets.SetDataset is
Also, what type of data set are using in this case? This page in our documentation goes over the differences:
Yes, I'm using GetDataset to get an editable copy. All the data are PI calculations.
A snippet of the code:
Dim dss As Datasets
Dim ds As Dataset
Dim i, nds As Integer
Dim ToReplaceServerM As String
Dim oBook As ProcBook
Set dss = oBook.Datasets 'get all data sets
nds = dss.Count 'number of data sets
For i = 1 To nds
Set ds = dss.GetDataset(i)
If ds.Type <> 3 Then '3 doesn't have a server name
If LCase(ds.ServerName) = ToReplaceServerM Then 'check if it's the server to replace and replace it
ds.ServerName = ReplacementServerRaw
dss.SetDataset (ds) 'Errors out here
It looks like the problem was caused by the parenthesis around the dataset when using SetDataset.
Removing them made the error go away.
Glad that helped. I did notice when I removed the parentheses in your example it resolved the error but I couldn't get it to actually edit any data sets that way, but my test may have had other discrepancies. With the code you posted, did it successfully edit the data sets as you intended after you removed the parenthesis?
Yes, it successfully edited the data sets after removing the parenthesis.
Retrieving data ...