问候优秀的头脑。
有时我必须在几个对象实例上创建或修改属性 这非常耗时,尤其是当您需要添加大量属性时 我尝试使用对象工具包,但它似乎要求您拥有完整版本的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) }