AnsweredAssumed Answered

How to create a new AFAttribute en AFBase programmatically ?

Question asked by jumeunier on Feb 18, 2015
Latest reply on Feb 19, 2015 by jumeunier



I try to update my AF database in C# .Net code with AFSDK and it doesn't really work.

To be precise, I try to add a new sub-attribute to an existing attribute already having many sub-attributes.

All those attributes use 'PI Point' DataReference, the PI tag name is the same as the attribute name.


AF Structure :








I would like to add a new sub-attribute to obtain :









Here's some testing code :

(I have a DAL class containing connection & querying methods for PI & AF)



string atr_parent = "Name_Of_Parent_Attribute";

string atr_name = "Name_Of_SubAttribute_To_Create";


// Retrieve parent attribute

AFElement elm = DAL.AFBase.Elements["Element_Name"];

AFAttribute af_parent = elm.Attributes[atr_parent];


// Create PI point before associating it to Attribute

string pi_point_name = atr_name;

if (DAL.mPiServer.PIPoints[pi_point_name] == null) {

    DAL.mPiServer.PIPoints.Add(pi_point_name, "classic", PointTypeConstants.pttypFloat32);



// Create sub_attribute to add

// Try n°1

AFAttribute af_sub = new AFAttribute(DAL.AFBase);

af_sub.Name = atr_name;



// => return the error "can't add dynamicly created AFAttribute to Collection"


// Try n°2 :

AFAttribute sibling = af_parent.Attributes[0];

AFAttribute af_sub = sibling;

af_sub.Name = atr_name;



// => return the error "Attribute already exists" (it's because they have same ID but ID property is read-only and I can't change it :/)



At that point, I tried to add this :

AFDataReference.CreateConfig(af_sub, true, myProgressHandler);

But it doesn't have any effect (the event in myProgressHandler says it didn't find attribute to configure)


So I still don't know how to create this new Attribute in AF database.

I will also need to give it the PIPoint DataRefence and set the ConfigString


// this line :

af_sub.ConfigString = @"\\PI_SERVER_NAME\" + pi_point_name + ";RelativeTime=-14d";

// => return the error : "can't change ConfigString if you don't have DataReference"


Of course, dataReference is read-only, too.

Setting the DataReferencePlugin property make the code to successfully compile, but it doesn't create my attribute


So, again, how do you create new AFAttribute and add it to an existing AF Database ?