From my understanding, you are referencing below method:
By looking at the method, I see two things. GetAttributeValue method needs to come from PI Point Class. Please see example from above link.
object drAttrValue; drAttrValue = myAttribute.PIPoint.GetAttribute(item);
Also PIPointClass.GetAttributeValue will get PI Point's attribute value meaning its attribute like (Location1, Pointsource, ExeMax...etc)
If you wanted to get the AF Attribute's value, then you need to use something similar to below:
I hope I am on the right track.
Thanks for the response, Jin. I only posted part of the code. The AF Wrapper code defines the AFW.GetCurrent Value function. I am really trying to get to the AF Structure from VBA.
I have dug deeper into the problem. It looks like there is a problem in handling Null returns or attributes. I have been using the wrapper function GetElementDescription and have been making changes or adding Returns to pin down the exact statement that triggered the error.
The code snippet from ProcessBook VBA that is failing is
Private Sub oContextHandler_ContextChanged(FromDisplay As Display, FromContexthandler As ContextHandler)
txtContext.Contents = oContextHandler.Name
elemdesc.Contents = AFW.Getelementdescription(oContextHandler.CurrentContext(ThisDisplay)) ' This is the line that fails (sometimes)
The code snippet from the Wrapper that I have gotten to is:
// Gets an element description for a given element path
public string GetElementDescription(string fullElementPath)
AFElement element = GetElement(fullElementPath);
if (element.Description != null ) return element.Description;
else return "No Description New ";
if (element != null && element.Description != null) return element.Description;
else return "No Description ";
The GetElement function seems to work, returning an element. The first IF statement I added. The second was in the original wrapper.
Further investigation revealed that referencing element.Description in any statement fails if the element description in AF is blank. But, if the element has a description, it works.
I confirmed this by changing the context to an element with a description and seeing success. I change the context to an element with no description and received an error. Then, I added a description to the failing element and repeated the test. This time, choosing the element where I added a description worked correctly.
I am not sure what is causing the failure that occurs when an element attribute that is null is referenced.
I changed the check on element.Description to a check for blank (not null), and the function worked.
if (element.Description == "") return "No Description New ";
else return element.Description;
not sure why checking for null triggered an error when the description is blank, but not when the description is not blank. Will need to look at the different functions to see whether to check for null or blank or other. Not sure why the wrapper functions do not work for me when they seem to be working for others when there is no description. now, i need to test the other functions.
You could check for string empty or null.
if (String.IsNullOrEmpty(element.Description)) ...
using your suggestion, I was able to check the return with no errors.
For some reason, I could not use the StringIsNullorEmpty(element.Description) in the if statement.
But, I created a boolean that I set to the StringIsNullorEmpty and then used the boolean in the if statement. Without this step, the compiler did not recognize IsNullorEmpty as being in String, but the autofill did find it.
Getting the function working required a series of discoveries, but that part of the Wrapper is working. Now to check the others and then do some extensions for children, grandchildren, values, etc.