Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Fabio Riera on July 10, 2013, 11:06:17 pm

Title: How to duplicate a package using Repository object
Post by: Fabio Riera on July 10, 2013, 11:06:17 pm
Hi there,

I'm creating an add-in for EA. One of my tasks is to duplicate a package (ctrl-C & ctrl-V) in project browser. How I do this task using the Repository object? The package to be duplicated is the object in context. Thanks in advance.

Title: Re: How to duplicate a package using Repository ob
Post by: qwerty on July 10, 2013, 11:11:41 pm
Check the package.clone method.

q,
Title: Re: How to duplicate a package using Repository ob
Post by: Fabio Riera on July 10, 2013, 11:16:57 pm
Thanks! And how I move the cloned package to another package? By changing its ParentID?
Title: Re: How to duplicate a package using Repository ob
Post by: Helmut Ortmann on July 10, 2013, 11:26:37 pm
Hi Fabio,

be aware: It may be no problem to clone a package. But I think this clone don't create new elements as it's content (shallow copy).

So you probably have to recursively dip into the package structure and clone all the elements and packages.

Helmut
Title: Re: How to duplicate a package using Repository ob
Post by: Geert Bellekens on July 10, 2013, 11:52:49 pm
I'm pretty sure it does, package.Clone has often been suggested as the solution to copying elements, but it would be nice to get a confirmation.

Geert
Title: Re: How to duplicate a package using Repository ob
Post by: qwerty on July 11, 2013, 12:18:10 am
I just tried it. clone works recursively.

q.
Title: Re: How to duplicate a package using Repository ob
Post by: Fabio Riera on July 11, 2013, 03:12:10 am
Hello,

I'm trying with this code:

            const int SOURCE_PACKAGE_ID = 227375;
            Package pckSource = MyRepository.GetPackageByID(SOURCE_PACKAGE_ID);
            Package pckClon = pckSource.Clone();

But pckClon is always null.

What I'm doing wrong?
Title: Re: How to duplicate a package using Repository ob
Post by: qwerty on July 11, 2013, 05:19:57 am
I tried it with VB and it works. You're missing an update at the end.

Maybe it's a security issue? Have you turned on security?

q.