111,092
社区成员




Public Function getAttr(ByVal obj As Object, ByVal attr_name As String) As Object
Dim attrs As Object
Dim attr As IAttribute
attrs = obj.AttrsEx1(True, False)
Dim i As Integer
For i = 0 To UBound(attrs)
attr = attrs(i)
If attr.Name = attr_name Then
Return attr
End If
Next
Return Nothing
End Function
Public Function getAttrValue(ByVal attr_point As IAttribute, ByVal type_str As String, Optional ByVal unit_str As Integer = 11) As String
getAttrValue = ""
If type_str = "Int" Then
getAttrValue = Str(attr_point.IntVal)
ElseIf type_str = "String" Then
getAttrValue = attr_point.StrVal
ElseIf type_str = "Length" Then
getAttrValue = Str(attr_point.Length(unit_str))
ElseIf type_str = "Double" Then
getAttrValue = Str(attr_point.DoubleVal)
ElseIf type_str = "AREA" Then
getAttrValue = Str(attr_point.Area(unit_str))
ElseIf type_str = "ENUM" Then
getAttrValue = attr_point.StrVal
ElseIf type_str = "Boolean" Then
getAttrValue = attr_point.BoolVal
End If
Return getAttrValue
End Function
Function setAttribute(ByVal obj As Object, ByVal attr_name As String, ByVal attr_type As String, ByVal attr_value As String, Optional ByVal attr_unit As Integer = 11) As Boolean
Dim attrMod As IAttributesModifier
attrMod = AM.AttributesModifier(obj)
If attr_type = "String" Then
Call attrMod.SetString(attr_name, attr_value)
ElseIf attr_type = "ENUM" Then
Call attrMod.SetString(attr_name, attr_value)
ElseIf attr_type = "Double" Then
Call attrMod.SetDouble(attr_name, attr_value)
ElseIf attr_type = "Length" Then
Call attrMod.SetLength(attr_name, attr_value, attr_unit)
ElseIf attr_type = "Int" Then
Call attrMod.SetInteger(attr_name, attr_value)
ElseIf attr_type = "Area" Then
Call attrMod.SetArea(attr_name, attr_value, attr_unit)
ElseIf attr_type = "Boolean" Then
Call attrMod.SetBoolean(attr_name, attr_value)
End If
attrMod.Run()
If statusCheck(attrMod) = False Then
Return False
End If
Return True
End Function
Public Function statusCheck(ByVal obj As Object) As Boolean
statusCheck = True
If obj.ErrorStatus <> 0 Then
MsgBox(obj.ErrorMessage)
Return False
End If
End Function
var attrs = obj.AttrsEx1(true, false);
IAttribute getAttr(object obj, string attr_name)
{
var attrs = obj.AttrsEx1(true, false);
foreach (var attr in attrs)
{
if (attr.Name = attr_name)
return attr;
}
}
string getAttrValue(IAttribute attr_point, string type_str, int unit_str = 11)
{
switch (type_str)
{
case "Int": return attr_point.IntVal.ToString();
//.....
default: return "";
}
}
bool setAttribute(object obj, string attr_name, string attr_type, string attr_value, int attr_unit = 11)
{
IAttributesModifier attrMod = AM.AttributesModifier(obj);
switch (attr_type)
{
case "String":
Call attrMod.SetString(attr_name, attr_value)
break;
//......
}
attrMod.Run();
if (!statusCheck(attrMod)) return false;
return true;
}
bool statusCheck(object obj)
{
if (obj.ErrorStatus != 0)
{
MessageBox.Show(obj.ErrorMessage);
return false;
}
return true;
}