ModifyAttributes Method (PIHeadingSet object)

             

 

The ModifyAttributes method changes the values of the passed attributes in the corresponding object on the Server.  The method provides a more efficient method to make multiple modifications then setting the attributes individually. Desired modifications are specified in the passed NamedValues collection where the each name is a property name and the value contains the new property value.

 

Syntax

object.ModifyAttributes nvsAttributes, hnvsErrors

   

The ModifyAttributes method syntax has these parts:

Part

Description

object

An object expression that evaluates to a PIHeadingSet.

nvsAttributes

NamedValues collection of attribute names and new values used to modify the object.

hnvsErrors

NamedValues collection of errors returned if there are problems.

 

Trappable Errors

In addition to generic errors (such as Out of Memory), the following errors may occur:

Error

Description

pseMODIFYATTRIBUTES

There was an error with ModifyAttributes. Check the errors (hnvsErrors) collection

 

Errors Collection Errors

Here are some of the errors that can be returned in the errors collection (hnvsErrors). The name of the NamedValue in the collection is the attribute name passed. The value is the error code:  

Error

Description

pseATTRIBUTENOTVALID

The attribute name passed wasn't valid.

pseINVALIDNAME

Name of the object is invalid.

 

Example

Here is an example demonstrating how to use ModifyAttributes. To build this example:

1. Create a new Visual Basic project and add a reference to the PISDK Library.

2. Cut and paste the code below into the project.

 

'

' This program adds a PIHeadingSet and a PIHeading to the Module Database.
' Then it uses ModifyAttributes to modify each of them.
'
Option Explicit
Dim g_UniqueNameCounter As Long

Private Sub Form_Load()
Dim piServer As Server
Dim headingSet As PIHeadingSet
Dim heading As PIHeading
Dim nameStr As String
Dim desStr As String
Dim levelStr As String
Dim nvsModAttr As NamedValues
Dim nvsErrors As NamedValues
'
' Intialize unique name counter
'
g_UniqueNameCounter = 1 ' intialize unique name counter
'
' Get the default server
'
Set piServer = PISDK.Servers.DefaultServer
'
' Add a PIHeadingSet using a unique name
'
Set headingSet = piServer.PIModuleDB.PIHeadingSets.Add(GenUniqueName(), "ModifyAttributes HeadingSet")
'
' Add a PIHeading to the PIHeadingSet
'
Set heading = headingSet.PIHeadings.Add(GenUniqueName(), "ModifyAttributes Heading", 1)
'
' Get ModifyAttributes strings once
'
nameStr = piServer.PIModuleDB.AttributeName(mbaName)
desStr = piServer.PIModuleDB.AttributeName(mbaDescription)
levelStr = piServer.PIModuleDB.AttributeName(mbaLevel)
'
' Modify the PIHeadingSet
'
Set nvsModAttr = New NamedValues
nvsModAttr.Add nameStr, ("New HeadingSet name")
nvsModAttr.Add desStr, ("New HeadingSet description")
headingSet.ModifyAttributes nvsModAttr, nvsErrors
'
' Modify the PIHeading
'
Set nvsModAttr = New NamedValues
nvsModAttr.Add nameStr, ("New Heading name")
nvsModAttr.Add desStr, ("New Heading description")
nvsModAttr.Add levelStr, (heading.Level + 1) ' add one to the level
heading.ModifyAttributes nvsModAttr, nvsErrors

End Sub

Function GenUniqueName() As String
'
' This function generates a unique name to avoid name collisions
'
Dim curTim As New PITime
Dim curDate As Date

curTim.SetToCurrent
curDate = curTim.LocalDate
GenUniqueName = Format(curDate, "yymmddhhmmss") & "-" & g_UniqueNameCounter
g_UniqueNameCounter = g_UniqueNameCounter + 1 ' increment this to make sure we get unique names

End Function

 

Enabling Operational Intelligence