NXObject.SetUserAttribute()是用于设置NXObject对象的属性,包括了多种类型,如字符串属性、整型属性、实值属性等等。
aggedObject[] taggedObjects = _FaceSelect.GetSelectedObjects(); Face face = (Face)taggedObjects[0]; //根据属性信息添加属性 NXObject.AttributeInformation attributeInformation = new NXObject.AttributeInformation(); attributeInformation.Type = NXObject.AttributeType.String; attributeInformation.Title = "Attribute_Face_1"; attributeInformation.StringValue = "Attribute_1_string"; face.SetUserAttribute(attributeInformation,Update.Option.Now); //添加int属性 string intTitle = "IntAttributeTitle"; int intValue = 1; face.SetUserAttribute(intTitle,0,intValue,Update.Option.Now); //添加double属性 string doubleTitle = "DoubleAttributeTitle"; double doubleValue = 2.1; face.SetUserAttribute(doubleTitle,0,doubleValue,Update.Option.Now); //添加字符串属性 string stringTitle = "StringAttributeTitle"; string stringValue = "stringValue"; face.SetUserAttribute(stringTitle,0,stringValue,Update.Option.Now);添加完成后,在面属性中可以看到如下:
查看一个面的所有属性,用 NXObject.AttributeInformation[] attributeInformation1 = face.GetUserAttributes();
NXObject.AttributeInformation[] attributeInformation1 = face.GetUserAttributes(); UFUi theUFUi = theUFSession.Ui; theUFUi.OpenListingWindow(); int i = 0; foreach(var ai in attributeInformation1) { if (ai.Type == NXObject.AttributeType.String) { theUFUi.WriteListingWindow(i++.ToString() + " " + ai.Title + " "+ai.StringValue+"\n"); } else if(ai.Type==NXObject.AttributeType.Integer) { theUFUi.WriteListingWindow(i++.ToString()+" "+ai.Title+" "+ai.IntegerValue.ToString()+" \n"); } else if (ai.Type == NXObject.AttributeType.Real) { theUFUi.WriteListingWindow(i++.ToString() + " " + ai.Title + " " + ai.RealValue.ToString() + " \n"); } }删除属性,NXObject.Delete***()
public void DeleteAllAttributesByType(AttributeType type); public void DeleteAllAttributesByType(AttributeType type, Update.Option option); public void DeleteAttributeByTypeAndTitle(AttributeType type, string title, Update.Option option); public void DeleteAttributeByTypeAndTitle(AttributeType type, string title); public void DeleteUserAttribute(AttributeType type, string title, bool deleteEntireArray, Update.Option option); public void DeleteUserAttributes(AttributeType type, Update.Option option); public void DeleteUserAttributes(AttributeIterator iterator, Update.Option option);