Book a Demo

Author Topic: Clone composite element  (Read 4734 times)

Dave.B

  • EA User
  • **
  • Posts: 94
  • Karma: +0/-0
    • View Profile
Clone composite element
« on: October 07, 2009, 08:53:23 pm »
I have the need to clone composite elements such that all of an elements diagrams and embedded elements are cloned to the new element.

The built in copy as new feature only clones the element and not its embedded elements and diagrams.

I'm therefore thinking that may be I could write a script to do this. But before I do this, I'd like to know if any one else has tried this and what are the difficulties. For example I see that an element (as presented by the automation interface) has many collections that I guess will need to be programatically cloned.

Any suggestions?

Thanks
Dave B.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Clone composite element
« Reply #1 on: October 07, 2009, 08:57:40 pm »
I've done something similar once (copying a structure that acted as a template) And I remember that some things just didn't work back then, but that could have been my fault entirely. (probably ;))

You know that you can achieve the same thing by using xmi export/import? (with strip GUID's ticked)
It's a bit cumbersome, but if you don't need to do it a lot it might be easier to go that way.

Geert

Dave.B

  • EA User
  • **
  • Posts: 94
  • Karma: +0/-0
    • View Profile
Re: Clone composite element
« Reply #2 on: October 07, 2009, 10:36:17 pm »
Geert,
Yes I did know about that method to clone a whole package. The trouble is that I'm working within a package.

Here's the plot:
I'm building a SysML domain model for my client that has several variants that will each be a product in a product line. I therefore plan to have a composite block representing each product and build an IBD for each out of the same set of blocks that represent the available functionality in these products.

I've built the IBD for one those products and it is massive (50+ A4 diagrams with ~380 embedded elements (ports + parts)). Since the other products in the product line are similar and I've modelled the most complex one first, it would be good to be able to clone it and then adjust it to suit.

I can't do the package export and import with strip GUIDs trick as each of the composite elements needs to share the same set of blocks for the part classifiers.

How that makes sense and illustrates the size of my problem.

Thanks
Dave B.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Clone composite element
« Reply #3 on: October 07, 2009, 10:43:45 pm »
Dave,

If you are carefull that should still work with the xmi export.
You will first have to put those elements you whish to duplicate in a seperate package. (and be carefull that none of the shared elements end up there.)
Then you can do an xmi export/import.
That should create duplicates for everything that is in the package, but not for referenced elements that are outside the package.

I would really try to get it done using the xmi export/import, because duplicating everything using the api will be a royal PITA because of all the little things you might forget to copy/clone.

Geert

Dave.B

  • EA User
  • **
  • Posts: 94
  • Karma: +0/-0
    • View Profile
Re: Clone composite element
« Reply #4 on: October 07, 2009, 11:19:54 pm »
Geert,
That thought came to me over lunch after posting my previous reply. I'll export my package and import it into a free standing .eap model and have a play with it to see what is possible.

Thanks for ideas!

Cheers
Dave B.

Dave.B

  • EA User
  • **
  • Posts: 94
  • Karma: +0/-0
    • View Profile
Re: Clone composite element
« Reply #5 on: October 08, 2009, 02:35:01 am »
Geert,
Yes that works! I placed my BDD's and the composite block (which includes its IBDs, ports, and parts) in to a nested package and exported it. I then reimported it with strip GUIDs and renamed the package and composite block. The part classifiers, being held in the parent package are shared between the two sets of composite block parts. Excellent!

I then have the option of moving the block and its BDDs from the nest package back up to the parent package if I want to persist with a flat model structure.

Thanks for the tip
Dave B.

PS Here's a VB Script to dump some useful info about an element, especially when its a composite one. Tested in EA v7.5.846.
Code: [Select]
option explicit

' Outputs to the script output tab some information about the selected element
' in the project browser. The original intent of the script is to inspect
' composite elements.

const otElement = 4

sub element_info()
      Repository.ClearOutput("Script")

      dim cnt
      dim el as EA.Element
      dim sel_el as EA.Element
      set sel_el = Repository.GetTreeSelectedObject
      
      if not sel_el is nothing and sel_el.ObjectType <> otElement then
            Session.Output("Must select an element in the Project Browser (selected type code is " & sel_el.ObjectType & ")")
            exit sub
      end if

      Session.Output("Element Name: " & sel_el.Name )
      Session.Output("Type: " & sel_el.Type )
      Session.Output("Attributes #: " & sel_el.Attributes.Count)
      Session.Output("AttributesEx #: "& sel_el.AttributesEx.Count)
      Session.Output("BaseClasses #: " & sel_el.BaseClasses.Count)
      Session.Output("Connectors #: " & sel_el.Connectors.Count)
      Session.Output("Constraints #: " & sel_el.Constraints.Count)
      Session.Output("ConstraintsEx #: " & sel_el.ConstraintsEx.Count)
      Session.Output("CustomProperties #: " & sel_el.CustomProperties.Count)
      Session.Output("Diagrams #: " & sel_el.Diagrams.Count)
      Session.Output("Efforts #: " & sel_el.Efforts.Count)
      Session.Output("Elements #: " & sel_el.Elements.Count)
      Session.Output("EmbeddedElements #: " & sel_el.EmbeddedElements.Count)
      Session.Output("Files #: " & sel_el.Files.Count)
      Session.Output("Issues #: " & sel_el.Issues.Count)
      Session.Output("Methods #: " & sel_el.Methods.Count)
      Session.Output("MethodsEx #: " & sel_el.MethodsEx.Count)
      Session.Output("Metrics #: " & sel_el.Metrics.Count)
      Session.Output("Partitions #: " & sel_el.Partitions.Count)
      Session.Output("Realizes #: " & sel_el.Realizes.Count)
      Session.Output("Requirements #: " & sel_el.Requirements.Count)
      Session.Output("RequirementsEx #: " & sel_el.RequirementsEx.Count)
      Session.Output("Resources #: " & sel_el.Resources.Count)
      Session.Output("Risks #: " & sel_el.Risks.Count)
      Session.Output("Scenarios #: " & sel_el.Scenarios.Count)
      Session.Output("StateTransitions #: " & sel_el.StateTransitions.Count)
      Session.Output("TaggedValues #: " & sel_el.TaggedValues.Count)
      Session.Output("TaggedValuesEx #: " & sel_el.TaggedValuesEx.Count)
      Session.Output("Tests #: " & sel_el.Tests.Count)

      Session.Output("")
      Session.Output("Elements collection:")            'NB Elements collection appears to be a superset of the EmbeddedElements collection
      cnt = 0
      dim parts, ports
      parts =0
      ports =0
      for each el in sel_el.Elements
            Session.Output("  Name: " & el.Name & " (" & el.Type & ")")
            cnt = cnt+1
            if el.type = "Part" then parts = parts +1
            if el.Type = "Port" then ports = ports +1
      next
      Session.Output(cnt & " elements (comprising " & parts & " parts, " & ports & " ports, and " & (cnt - parts - ports) & " others)")

end sub

element_info