Author Topic: Difference between a copy and a instance?  (Read 2601 times)

Alika87

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Difference between a copy and a instance?
« on: July 19, 2013, 02:22:15 am »
hi guys,

My task requires that i am able to reproduce whole package, with all diagramms, the relations between them and all attributes + operations.

I thought: http://blog.sparxsystems.de/2010/02/ea-8-0-feature-kopieren-von-packages-im-ea/

Following this instructions would do. Copying them by stripping the GUIDs, would have effect, that the classes/objects are not an exact copy, more than an class by themselfes, because  their ID's are diffenrent. Seemed for me to be a fast an easy way to reproduce die Diagrams. I showed that to my person in charge, but he said its just a partial solution, because we need all Attribut of a class, including all inherited one from the mother-class, grandmother-class and so on. And this copies dont give that, thats why we need instances.

What do you think about that and do you know a way to automatically generate instances of a class?

Thank you for reading and hopefully i was able to explain myself in a proper way.

Helmut Ortmann

  • EA User
  • **
  • Posts: 928
  • Karma: +39/-1
    • View Profile
Re: Difference between a copy and a instance?
« Reply #1 on: July 19, 2013, 04:30:18 am »
Hi,

copy package makes a new set of identical elements with a new identity (new GUID and ID). It copies everything regardless of class, instance or whatever.

Export to *.xml and reimport it with stripping the GUID makes the same. New elements that are exactly the same but with a new identity.

It also copies all features (operation, attributes,..) and all relationships.

If you want to make an instance of a class just drag the class on a diagram and choose Instance. If the dialog don't appears press the CTRL/Strg key during the dragging.

If you want to do it frequently for whole packages consider writing:
- an Addin
- a Script
- a Transformation

I'm not sure I understand your problem.

An Instance is the instantiating of a class. Let's have a class 'chair'. The instances might be 'myChair:chair', 'redChair:chair' or .. Before the colon is the name of the instance (blank is also allowed). Behind the colon is the class the instance is derived from.

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

Alika87

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Difference between a copy and a instance?
« Reply #2 on: July 31, 2013, 08:08:54 pm »
Thanks for your reply Helmut.

You guessed it right and gave some useful hints. Like you suggested, I am writing now an AddIn for Enterprise Architect, that can automatically generates instances of a whole package. Can you give me any hint, where to start. I know how I can get access to the diagrams over the Repository, but at the moment I dont know how the create instances of the selected Diagrams, plus the according Connectors.

qwerty

  • EA Guru
  • *****
  • Posts: 9836
  • Karma: +190/-155
  • I'm no guru at all
    • View Profile
Re: Difference between a copy and a instance?
« Reply #3 on: July 31, 2013, 08:46:02 pm »
An instance is a copy of a class being Object (or whatever) as Type and having ClassifierID being the ObjectID of the original class. Connectors need to be duplicated manually (depends what you're doing).

If you want a smarter entry into EA's API have a look in my Scripting book.

q.
« Last Edit: July 31, 2013, 08:49:24 pm by qwerty »

Alika87

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Difference between a copy and a instance?
« Reply #4 on: July 31, 2013, 11:40:21 pm »
Quote
An instance is a copy of a class being Object (or whatever) as Type and having ClassifierID being the ObjectID of the original class. Connectors need to be duplicated manually (depends what you're doing).

If you want a smarter entry into EA's API have a look in my Scripting book.

q.

I started to try some solutions. At first I wanted to clone my Package and recursively Add new Elements to the new Package.

Now I encounter a probably trivial failure. My Compiler tells me, that there is no method named Clone in EA.Package, though the UserGuide tells me, that there is a Method called Clone. Do I have to include any special Reference to use this Clone-Method?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8623
  • Karma: +211/-26
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Difference between a copy and a instance?
« Reply #5 on: July 31, 2013, 11:48:34 pm »
Are you sure you are using the correct version of the Interop.EA.dll?
Mine has version 2.10.238.1 and contains EA.Package.Clone

Geert

Alika87

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Difference between a copy and a instance?
« Reply #6 on: July 31, 2013, 11:53:41 pm »
Quote
Are you sure you are using the correct version of the Interop.EA.dll?
Mine has version 2.10.238.1 and contains EA.Package.Clone

Geert

I got the same version you have. No matter what I tried, couldn't see the Clone-Method anywhere.

qwerty

  • EA Guru
  • *****
  • Posts: 9836
  • Karma: +190/-155
  • I'm no guru at all
    • View Profile
Re: Difference between a copy and a instance?
« Reply #7 on: August 01, 2013, 12:25:19 am »
Can't you just pretend the method exists? I mean the compiler should not really care unless the linker croaks.

q.

Simon M

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6497
  • Karma: +57/-6
    • View Profile
Re: Difference between a copy and a instance?
« Reply #8 on: August 01, 2013, 08:47:53 am »
Quote
I showed that to my person in charge, but he said its just a partial solution, because we need all Attribut of a class, including all inherited one from the mother-class, grandmother-class and so on.
Via the gui if you copy any element(s) and paste as new (Ctrl+Shift+V) generalizations are copied so you get this effect.

Simon

support@sparxsystems.com

Alika87

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Difference between a copy and a instance?
« Reply #9 on: August 01, 2013, 06:56:31 pm »
Quote
Can't you just pretend the method exists? I mean the compiler should not really care unless the linker croaks.

q.

I just excluded the Interop.EA.dll and icluded it again. Now it finds the Clone-Method. Interesting.

Alika87

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Difference between a copy and a instance?
« Reply #10 on: August 01, 2013, 08:20:19 pm »
I try to explain my problem more exactly. I got a MetaModel with several Classes, all of them have different Cardinalities ranging from 1...*. Now I want to create automatically with an AddIn, Instances of this classes with a Cardinality of 1.

At first I tried the lazy method. Clone the Package, then iterate through the Classdiagrams and try to change the Multiplicity of the class to 1. I dont know how correct this idea is, but I couldn't implement it, because I couldnt find any instruction to change multiplicity.

My second idea is(probably the more correct one) is the create a new Package and iteratively Add the class diagrams of my MetaModel into my new created package. I looked up in the help guide and other resourcese at the EA-Website an couldnt find a method for creating oder Adding new Items(in this case classes).

Am I missing something? Guys I dont want to bother you much longer and neither I want to ask for a finished solution. It would be nice if you could give me some hints. At the moment I am stucked in this deadend and wanna get out of it.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8623
  • Karma: +211/-26
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Difference between a copy and a instance?
« Reply #11 on: August 01, 2013, 08:44:10 pm »
Addin new things via the API always goes through the magical EA.Collection.AddNew()

So if you want to add a new element to a package you do myPackage.Elements.AddNew()

If you want to add a new attribute to a class you do myClass.Attributes.AddNew()

If you wan to ..... euh, you get the picture ;D

Geert

Alika87

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Difference between a copy and a instance?
« Reply #12 on: August 01, 2013, 09:34:20 pm »
Quote
Addin new things via the API always goes through the magical EA.Collection.AddNew()

So if you want to add a new element to a package you do myPackage.Elements.AddNew()

If you want to add a new attribute to a class you do myClass.Attributes.AddNew()

If you wan to ..... euh, you get the picture ;D

Geert

thanks for that picture :D

Alika87

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Difference between a copy and a instance?
« Reply #13 on: August 21, 2013, 11:37:46 pm »
Sorry for bringing up this Topic again. I got a small question, that really bothers me. I want to add some classes and packages automatically, so I am writing a small AddIn. I strictly followed the instructions of EA for adding something.  When I run the AddIn, the package and also the class diagram is generated, but no elements and I receive a failure message: EA_MenuClick: Invalid Type. I am sure the reason is not far away, but i cannot see it. Thanks a lot.          

myPackage = Repository.GetTreeSelectedPackage();
newPackage = myPackage2.Packages.AddNew(myPackage.Name.ToString(), "");
newPackage.Update();
EA.Diagram diagram;
EA.Element o;
EA.DiagramObject v;
diagram = newPack.Diagrams.AddNew(newPack.Name.ToString(), "class");
diagram.Update();
o = newPack.Elements.AddNew("App", "class");
o.Update();
v = diagram.DiagramObjects.AddNew(o.Name.ToString(), o.Type.ToString());
v.ElementID = o.ElementID;
v.Update();
newPack.Diagrams.Refresh();

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8623
  • Karma: +211/-26
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Difference between a copy and a instance?
« Reply #14 on: August 26, 2013, 09:22:22 pm »
Try debugging, that works better then asking a bunch of random strangers on a forum.

Geert