1

问候上级思想。

有时我必须创建或修改几个对象实例的属性。
这真的很耗时,尤其是当您需要添加大量属性时。
我尝试使用对象工具包,但似乎它需要您拥有完整版本的 Visual Studio,而不仅仅是 Visual Studio Express/Community。

有没有人有任何指示或我可以研究的东西来减少这个过程的工作量?

到目前为止,我已经编写了一个小的 Ruby 脚本来简化这个过程,但我怀疑可能会有更简单的东西。

    tag_name = "My_Tag_Name"
    template_name = "$b_UserDefined"
    attributes = [[5, "float", "0.0", "UDA_DAM", "Level for Dam"],
                  [2, "float", "1.0", "UDA_DAM_ML", "The size of the dam"],
                  [8, "bool", "FALSE", "UDA_FLAG", "Flag bit for Dam"],
                  [1, "string", "A String", "UDA_STRING", "A Random String"]]
    #             [quantity, type, default value, name, description]

    portion_0 = p %{; Go to: "Galaxy" > "Import" > "Galaxy Load"
    ; Created by 
    :TEMPLATE=#{template_name}
    :Tagname,UDAs}   # The template
    portion_1 = p %{\n#{tag_name},"<UDAInfo>}  # The UDA Info
    portion_2 = ""  # The Values


    # UDAs
    attributes.each_with_index do |attrib, i|
      repeat_nr = attrib[0]
      (1..repeat_nr).each do |j|
        if attrib[1] == "bool"
          portion_0 += p %{,#{attrib[3]}#{j.to_s.rjust(2, '0')},#{attrib[3]}#{j.to_s.rjust(2, '0')}.Description}
          portion_1 += p %{<Attribute Name=""#{attrib[3]}#{j.to_s.rjust(2, '0')}" DataType=""MxBoolean"" Category=""MxCategoryWriteable_USC_Lockable"" Security=""MxSecurityOperate"" IsArray=""false"" HasBuffer=""false"" ArrayElementCount=""0"" InheritedFromTagName=""""/>}
          portion_2 += p %{,#{attrib[2]},#{attrib[4]} #{j.to_s.rjust(2, '0')}}
        elsif attrib[1] == "string"
          portion_0 += p %{,#{attrib[3]}#{j.to_s.rjust(2, '0')},#{attrib[3]}#{j.to_s.rjust(2, '0')}.Description}
          portion_1 += p %{<Attribute Name=""#{attrib[3]}#{j.to_s.rjust(2, '0')}"" DataType=""MxString"" Category=""MxCategoryWriteable_USC_Lockable"" Security=""MxSecurityOperate"" IsArray=""false"" HasBuffer=""false"" ArrayElementCount=""0"" InheritedFromTagName=""""/>}
          portion_2 += p %{,#{attrib[2]},#{attrib[4]} #{j.to_s.rjust(2, '0')}}
        elsif attrib[1] == "float"
          portion_0 += p %{,#{attrib[3]}#{j.to_s.rjust(2, '0')},#{attrib[3]}#{j.to_s.rjust(2, '0')}.Description}
          portion_1 += p %{<Attribute Name=""#{attrib[3]}#{j.to_s.rjust(2, '0')}"" DataType=""MxFloat"" Category=""MxCategoryWriteable_USC_Lockable"" Security=""MxSecurityOperate"" IsArray=""false"" HasBuffer=""false"" ArrayElementCount=""0"" InheritedFromTagName=""""/>}
          portion_2 += p %{,#{attrib[2]},#{attrib[4]} #{j.to_s.rjust(2, '0')}}
        end
      end
    end
    portion_1 += "</UDAInfo>\""

    script = portion_0 + portion_1 + portion_2

    file_name = p %{Import this file #{Time.now.strftime("%Y-%m-%d %Hh%M_%S")}.csv}

    File.open(file_name, 'w') { |f| f.write(script) }
4

0 回答 0