środa, 20 marca 2013

why python for Visum scripting - short answer

that's why

task:
check if UDA exists

code:
def CheckAttr(obj,attr):
       return attr in [e.Code for e in o.Attributes.GetAll]


usage:

CheckAttr(Visum.Net.Links,"ToNodeNo")


with VB, or anything lower level it'd be at least 20 lines of code :P


Update - the same with VB:

Sub UpdateVisumUDAs(ByVal tableName As String _
   , ByVal keyFields As String() _
   , ByRef ds As DataSource _
   , Optional ByVal CreateUDA As Boolean = True _
   , Optional ByVal ValueType As Integer = 5)


Dim o As Object = ds.StringToVisumObject(tableName, ds)
Dim Attributes As Object()
Attributes = o.Attributes.GetAll
Dim AttrCodes As New List(Of String)
For Each Attribute As Object In Attributes
   AttrCodes.Add(Attribute.Code.ToString.ToUpper)
Next
For Each key As String In keyFields
   If CreateUDA AndAlso Not AttrCodes.Contains(key.ToString) Then
   o.AddUserDefinedAttribute(key.ToString, key.ToString, key.ToString, ValueType)
End If
Next


PS. Don't take me as an ignorant - I know more or less pros and cons for python vs. any 'proper' programming language, but I just love the way you can do things in python


Brak komentarzy:

Prześlij komentarz