5 Replies Latest reply on Oct 28, 2016 7:47 PM by Steve Boyko

    Create a New Event Frame Based on an Existing Frame

    Steve Boyko

      Maybe this is a dumb question but I can't find an easy way to do this.

       

      Suppose I have an existing event frame, and I'd like to create a new event frame using VB.NET that is almost the same as the existing one, but with the start and end times changed.

       

      Is there a simple way to do that without doing a bunch of copying like:

      Dim origEF As AFEventFrame = AFEventFrame.FindEventFrame(afSrv, efGUID)

      Dim newEF As New AFEventFrame(origEF.Database, "split", origEF.Template)

      newEF.SetStartTime(x)

      newEF.SetEndTime(y)

      For Each attr In origEF.Attributes

          newEF.Attributes.Add(attr)

      Next

      Thanks for any help you can provide!

        • Re: Create a New Event Frame Based on an Existing Frame
          Eugene Lee

          Hi Steve,

           

          Since you are already creating the new event frame based on the template of the original event frame. You do not need this part of the code at all.

          For Each attr In origEF.Attributes
              newEF.Attributes.Add(attr)
          Next
          

           

          The attributes should already be there.

          2 of 2 people found this helpful
            • Re: Create a New Event Frame Based on an Existing Frame
              Rick Davin

              Good points, Eugene.  Forgive me for being THAT GUY but ...

               

              If the event frame template allows extensions, then there could be non-templated attributes on the origEF.  So really the code should be changed to:

               

              For Each attr In origEF.Attributes  
                  if (attr.Template == null)
                  {
                      newEF.Attributes.Add(attr)  
                  }
              Next 
              

               

               

              Plus it depends on how much Steve wants to copy from the origEF.  If Steve wants the new EF to include the referenced elements, especially the primary referenced element, he would need to copy those properties from origEF as well.

               

              Rick

              2 of 2 people found this helpful
                • Re: Create a New Event Frame Based on an Existing Frame
                  Steve Boyko

                  Thanks Rick Davin and Eugene Lee! Here's how the code finally fell out:

                   

                  Dim origEF As AFEventFrame = AFEventFrame.FindEventFrame(afSrv, efGUID)

                  Dim newEF As New AFEventFrame(origEF.Database, "split", origEF.Template)

                  newEF.SetStartTime(x)

                  newEF.SetEndTime(y)

                  For Each attr In origEF.Attributes

                      newEF.Attributes(attr.Name).SetValue(attr.GetValue())

                  Next

                  ' Overwrite any attributes that we want unique to this copy, not copied from the original

                  newEF.Attributes("attrib-in-template").SetValue(New AFValue("unique-value"))

                  ' Copy referenced elements

                  For Each el In origEF.ReferencedElements

                          newEF.ReferencedElements.Add(el)

                      Next

                  newEF.PrimaryReferencedElement = origEF.PrimaryReferencedElement

                   

                  Good tip on copying over any extensions to the template!

                  1 of 1 people found this helpful