Book a Demo

Author Topic: Cloning of an element  (Read 8493 times)

Clemo

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Cloning of an element
« on: July 10, 2014, 07:13:00 pm »
Hi,

I have a hierarchical model

A->B->C

For business reasons we are creating two models

Model 1 : A->B

Model 2 : B->C

within the same project and the models are created automatically by parsing a CSV file.

I now need to have the B's in the model not to share the same element ID but have separate ones, hence when I create a model 2 element B, I think I need to make a clone of the Model 1:B rather than link to it or is there an easier way.

Is there any easy way to do this as it appears there is no cloning method on the Element class

Thanks

Clemo


Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Cloning of an element
« Reply #1 on: July 10, 2014, 07:21:12 pm »
Hi Clemo,

cloning a package is quite simple.

1. Package Browser
Use Copy and Paste for a package. The package and the nested packages are cloned.

2. Export / Import *.xml
Copy Package (recursive) to XML and import it at another location in the project tree. At start of import don't forget to click on Strip GUID. The result is:
The package is cloned to the new location. Each element is new but has the same features as before.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Clemo

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Cloning of an element
« Reply #2 on: July 10, 2014, 08:42:36 pm »
Hi Helmut,

Thanks for the reply.

However, I am trying to do this automatically via the Java API rather than manually as you propose.

Apologies for not making that aspect of my question clearer

Clemo

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Cloning of an element
« Reply #3 on: July 10, 2014, 10:33:40 pm »
Hi Clemo,

you may try export/import via API. It may work but I haven't tried it before.

Cloning a Package don't looks as an easy tasks. There are a lot undocumented features used in EA and it will properly take you some time to get a general clone working.

If you know the possible package content then it might be possible (reducing of complexity to your issue).

Try to search the forum for example Clone.

If you find a solution please post it hear. I think there are some people also interesd in a viable solution.

Helmut

Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Cloning of an element
« Reply #4 on: July 11, 2014, 12:50:41 am »
There is a Repos.Clone method (IIRC) for packages.

q.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Cloning of an element
« Reply #5 on: July 11, 2014, 01:09:32 am »
Hi q,

great. There is always something to learn.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Cloning of an element
« Reply #6 on: July 11, 2014, 05:10:00 am »
Yes, Helmut. One never stops learning :-)

I'd wish the API designer(s) from Sparx would have taken the design more seriously and created a Clone, Delete (and whatever) method for each thing (be it element, package or connector) in EA. The current design is simply poor :( I have seen worse designs, but that's no excuse.

q.

Clemo

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Cloning of an element
« Reply #7 on: July 11, 2014, 11:06:42 pm »
Hi Guys,

The clone is at a package level, I wanted to clone at an element level, is CloneNode the correct method to use?

Clemo

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Cloning of an element
« Reply #8 on: July 11, 2014, 11:20:18 pm »
Hi Clemo,

the element don't contains any .Clone() method.

Only the package contains a .Clone() method. Because you can only call this method from a package there is no chance to clone an element alone.

You may do the following:
- Create a new empty package
- Move element to empty package
- Clone package
- Move old element back to his old location
- Move/rename cloned element to the wanted location

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)