预订演示

请注意 : 本帮助页面不适用于最新版本的Enterprise Architect. 最新的帮助文档在这里.

前页 后页

Element Extras

These are examples of code to access and use element extras, such as scenarios, constraints and requirements.

Sub ElementExtras
     Dim element as object
     Dim o as object
     Dim idx as Integer
     Dim bDel as boolean
     bDel = true

     try
          element = m_Repository.GetElementByID(129)

          'manage constraints for an element
          'demonstrate addnew and delete
          o = element.Constraints.AddNew("Appended","Type")
          If not o.Update Then
               Console.WriteLine("Constraint error:" + o.GetLastError())
          End if
          element.Constraints.Refresh
          For idx = 0 to element.Constraints.Count -1
               o = element.Constraints.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="Appended") Then
                    If bDel Then element.Constraints.Delete (idx)
               End if
          Next

          'efforts
          o = element.Efforts.AddNew("Appended","Type")
          If not o.Update Then
               Console.WriteLine("Efforts error:" + o.GetLastError())
          End if
          element.Efforts.Refresh
          For idx = 0 to element.Efforts.Count -1
               o = element.Efforts.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="Appended") Then
                    If bDel Then element.Efforts.Delete (idx)
               End if
          Next

          'Risks
          o = element.Risks.AddNew("Appended","Type")
          If not o.Update Then
               Console.WriteLine("Risks error:" + o.GetLastError())
          End if
          element.Risks.Refresh
          For idx = 0 to element.Risks.Count -1
               o = element.Risks.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="Appended") Then
                    If bDel Then element.Risks.Delete (idx)
               End if
          Next

          'Metrics
          o = element.Metrics.AddNew("Appended","Change")
          If not o.Update Then
               Console.WriteLine("Metrics error:" + o.GetLastError())
          End if
          element.Metrics.Refresh
          For idx = 0 to element.Metrics.Count -1
               o = element.Metrics.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="Appended") Then
                    If bDel Then element.Metrics.Delete (idx)
               End if
          Next

          'TaggedValues
          o = element.TaggedValues.AddNew("Appended","Change")
          If not o.Update Then
               Console.WriteLine("TaggedValues error:" + o.GetLastError())
          End if
          element.TaggedValues.Refresh
          For idx = 0 to element.TaggedValues.Count -1
               o = element.TaggedValues.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="Appended") Then
                    If bDel Then element.TaggedValues.Delete (idx)
               End if
          Next

          'Scenarios
          o = element.Scenarios.AddNew("Appended","Change")
          If not o.Update Then
               Console.WriteLine("Scenarios error:" + o.GetLastError())
          End if
          element.Scenarios.Refresh
          For idx = 0 to element.Scenarios.Count -1
               o = element.Scenarios.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="Appended") Then
                    If bDel Then element.Scenarios.Delete (idx)
               End if
          Next

          'Files
          o = element.Files.AddNew("MyFile","doc")
          If not o.Update Then
               Console.WriteLine("Files error:" + o.GetLastError())
          End if
          element.Files.Refresh
          For idx = 0 to element.Files.Count -1
               o = element.Files.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="MyFile") Then
                    If bDel Then element.Files.Delete (idx)
               End if
          Next

          'Tests
          o = element.Tests.AddNew("TestPlan","Load")
          If not o.Update Then
               Console.WriteLine("Tests error:" + o.GetLastError())
          End if
          element.Tests.Refresh
          For idx = 0 to element.Tests.Count -1
               o = element.Tests.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="TestPlan") Then
                    If bDel Then element.Tests.Delete (idx)
               End if
          Next

          'Defect
          o = element.Issues.AddNew("Broken","Defect")
          If not o.Update Then
               Console.WriteLine("Issues error:" + o.GetLastError())
          End if
          element.Issues.Refresh
          For idx = 0 to element.Issues.Count -1
               o = element.Issues.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="Broken") Then
                    If bDel Then element.Issues.Delete (idx)
               End if
          Next

          'Change
          o = element.Issues.AddNew("Change","Change")
          If not o.Update Then
               Console.WriteLine("Issues error:" + o.GetLastError())
          End if
          element.Issues.Refresh
          For idx = 0 to element.Issues.Count -1
               o = element.Issues.GetAt(idx)
               Console.WriteLine(o.Name)
               If(o.Name="Change") Then
                    If bDel Then element.Issues.Delete (idx)
               End if
          Next

     catch e as exception
          Console.WriteLine(element.Methods.GetLastError())
          Console.WriteLine(e)
     End try

End Sub