6 Replies Latest reply on Aug 10, 2010 2:32 AM by hanyong

    Accessing Attributes from AFTreeView

    PIAdminUnison

      Hi All,

       

      I have an AFTreeview loaded with the elements I want to see and their associated attributes.  What I am trying to accomplish is when I click on the attributes themselves, either an AF UI or a custom display shows the attributes value with timestamp and UOM.  I tried to use the AFtreeview's selected node but that seems to default to the element only and doesn't tell me which attribute I have selected.  I then tried to parse the ToolTip to get the selected attribute, but these seems to me to be the wrong way to approach it.  Once I have the values displayed (i.e. - GetValue().Value), I also want to edit the value if it is allowed.  I am doing this in VB.Net 2008 and using AF 2.1.x Any suggestions?

       

      Thanks in advance,

       

      Jimmy

        • Re: Accessing Attributes from AFTreeView
          hanyong

          Hi Jimmy,

           

          Since you want the information to be display, I assume you want to (or perhaps have already) implement AFTreeView_AfterSelect event. This gets triggered when user select a node (AFElement or AFAttribute) in the AFTreeView. You can get the selected node from the event arguments (TreeViewEventArgs) and handle the different cases appropriately, like the following:

          Private Sub AfTreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) 
                                     Handles AfTreeView1.AfterSelect
            Dim _SelectedNode As AFTreeNode = DirectCast(e.Node, AFTreeNode)
            If _SelectedNode.AFObject.GetType().Name = "AFAttribute" Then
              ' if selected node is an AFAttribute
              Dim _AFAttribute As AFAttribute = DirectCast(_SelectedNode.AFObject, AFAttribute)
              ' use AFViewControl to show the property of the attribute
              AfViewControl1.AFSetObject(_AFAttribute, Nothing, Nothing, Nothing)
            ElseIf _SelectedNode.AFObject.GetType().Name = "AFElement" Then
              Dim _AFElement As AFElement = DirectCast(_SelectedNode.AFObject, AFElement)
              ' use AFViewControl to show the property of the element
              AfViewControl1.AFSetObject(_AFElement, Nothing, Nothing, Nothing)
            End If
          End Sub

          I am using AFViewControl to display the AFAttribute or AFElement information here, one of the AF UI controls that can be used easily to display information of AFObjects.

            • Re: Accessing Attributes from AFTreeView
              PIAdminUnison

              Hi Han,

               

              Thanks for the code.  Quick question; will the AFViewControl allow me to set the value of a tag if it's ReadOnly=False?

               

              Jimmy

                • Re: Accessing Attributes from AFTreeView
                  hanyong

                  Yes, it is allowed. Another consideration on top of "ReadOnly=False" is that the user should have sufficient rights to do that as well. if user does not have the sufficient rights to write/make changes to AF, the fields would be greyed out. 

                    • Re: Accessing Attributes from AFTreeView
                      cmanhard

                      All these must be true before you can write a value to a PI Point from the ViewControl:

                       

                      1) PI Point Data Reference must be configure so "ReadOnly=False"

                       

                      2) User must have "Write Data" security privileges in the element

                       

                      3) User must have "Write" privilege for PI Point Data Security

                       

                      4) The ViewControl.ReadOnly flag must be set to false

                        • Re: Accessing Attributes from AFTreeView
                          PIAdminUnison

                          Quick question about point 3.  For point 2, I just have to grab my AFSecurity for the element and call the CanWriteData object to check to see if the current user can "write data".  Is there a similar object in the AFSecurity for this or do I have to do it through the PI SDK?

                           

                          Jimmy

                            • Re: Accessing Attributes from AFTreeView
                              hanyong

                              The "Write" privilege for PI Point Data Security that Chris mentioned is part of the PI Point configuration so you will have to use PI SDK to access this information. Specifically you will have to access the "DataSecurity" attribute to find what privilege PIusers or PIidentities have to the PI Point. 

                              ' get pipoint from AF attribute
                              Dim _PIPoint As PISDK.PIPoint = _AFAttribute.RawPIPoint
                              If Not _PIPoint Is Nothing Then
                                  MessageBox.Show(_PIPoint.PointAttributes("datasecurity").Value.ToString())
                              End If

                              If you have a version of PI server older than 3.4.380 then the relavant attribute should be "DataAccess", "DataOwner" and "DataGroup" instead. You probably have to have an idea what PIuser/PIidentity that the user will be mapped/trusted as well. These will be more related to security configuration on the PI server.

                               

                              If user have sufficient privileges for point 1, 2 and 4 that Chris pointed out but not point 3, the user should see a error dialog box that indicate that he/she do not have write privilege to the PI Point.
                              AFUI_2D00_Error.jpg