Sparx Systems Forum

Discussion => Automation Interface, Add-Ins and Tools => Topic started by: bilon on December 05, 2017, 10:37:41 pm

Title: How to duplicate element from script
Post by: bilon 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".
Title: Re: How to duplicate element from script
Post by: qwerty 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.
Title: Re: How to duplicate element from script
Post by: bilon on December 06, 2017, 12:05:23 am
Looks to be pretty hard work  :(
Title: Re: How to duplicate element from script
Post by: qwerty 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.
Title: Re: How to duplicate element from script
Post by: bilon on December 06, 2017, 02:30:08 am
Same as the original.
Title: Re: How to duplicate element from script
Post by: Uffe 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
Title: Re: How to duplicate element from script
Post by: bilon 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?
Title: Re: How to duplicate element from script
Post by: Geert Bellekens 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
Title: Re: How to duplicate element from script
Post by: Paolo F Cantoni 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