Author Topic: How to duplicate element from script  (Read 91 times)

bilon

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
How to duplicate element from script
« on: December 05, 2017, 10:37:41 pm »
Any idea how duplicate element from script? I need to do in script the same as do the browser functions "Copy element to clipboard" and "Paste element from clipboard".

qwerty

  • EA Guru
  • *****
  • Posts: 8958
  • Karma: +136/-123
  • I'm no guru at all
    • View Profile
Re: How to duplicate element from script
« Reply #1 on: December 05, 2017, 11:43:10 pm »
There's only the clone operation for Package. Use that to create a clone package and remove the unneeded. Eventually you

- create a dummy package for what you need to clone,
- place the element in,
- clone,
- move things back,
- move the cloned elements and
- remove the clone and dummy package.

Or you just create a clone bit by bit.

q.

bilon

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: How to duplicate element from script
« Reply #2 on: December 06, 2017, 12:05:23 am »
Looks to be pretty hard work  :(

qwerty

  • EA Guru
  • *****
  • Posts: 8958
  • Karma: +136/-123
  • I'm no guru at all
    • View Profile
Re: How to duplicate element from script
« Reply #3 on: December 06, 2017, 12:18:15 am »
Cloning is not that trivial as it seems the first sight. Elements can be connected, they can be used as types and other weird things. Now if you create a clone, what properties will the clone have?

q.

bilon

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: How to duplicate element from script
« Reply #4 on: December 06, 2017, 02:30:08 am »
Same as the original.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1070
  • Karma: +81/-5
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to duplicate element from script
« Reply #5 on: December 06, 2017, 02:41:58 am »
qwerty's point is that the element structure is complex, and the API does not have a Clone() feature. The simple workaround is to create a temp package and clone that, as Q suggested.

/Uffe
My theories are always correct, just apply them to the right reality.

bilon

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: How to duplicate element from script
« Reply #6 on: December 06, 2017, 03:05:16 am »
In my case, the elements are relatively simple, so I can't see any problems in duplication. Anyway, if duplication is possible through user interface, why it is not possible in scripting?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7731
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to duplicate element from script
« Reply #7 on: December 06, 2017, 03:16:21 am »
In my case, the elements are relatively simple, so I can't see any problems in duplication. Anyway, if duplication is possible through user interface, why it is not possible in scripting?

It is possible, just not as simple as you thought it would be.
And "why?" is simply because it hasn't been exposed in the API.

Geert

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 5874
  • Karma: +71/-77
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to duplicate element from script
« Reply #8 on: December 06, 2017, 10:54:32 am »
As usual, it is EXACTLY a matter of semantics.  As you have seen in the discussion there is a divergence on what the terms duplicate, clone, copy and paste mean.

Most of the "old timers" know that the element object isn't the whole story regarding the semantics of the element.  The relationships and other properties also play a part.  The semantics of "copy and paste" in the simple case ONLY make a copy of the element.  In Sparx EA terms, cloning means copying the object, its properties and relationships.  "Duplication" isn't really a valid concept since the resulting clone is not an exact copy, but a "doppelganger".

So if all you want to do is make a second element with all the same properties as the original but none of the relationships, then that's relatively simple.  Otherwise, as the others have said it's trickier than it first looks.

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!