Book a Demo

Author Topic: How do I move multiple elements across packages?  (Read 6439 times)

motivatedgorilla

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
How do I move multiple elements across packages?
« on: February 12, 2014, 01:26:05 pm »
Using the SQL builder, I am presented with a list of elements. These elements are located in different packages across the model. I need to move them into a specific package. Considering that there are over a 1000 elements, doing it manually seems highly inefficient. Is there a way to achieve this without the use of the API?

RoyC

  • EA Administrator
  • EA Practitioner
  • *****
  • Posts: 1297
  • Karma: +21/-4
  • Read The Help!
    • View Profile
Re: How do I move multiple elements across package
« Reply #1 on: February 12, 2014, 02:28:47 pm »
Perhaps you could provide more information on why the elements are in the wrong Packages, how many Packages they are spread across, and why you need to put them in the 'right' Package?

There are good reasons for holding specific elements in specific Packages, but I'm not sure that many (any?) are 'show stoppers' if the distribution turns out wrong. As you have found, you can easily assemble a list of elements having a particular property, and you can work on these elements from such lists, so their physical location might not be important.

You can multiple-select elements in one Package in the Project Browser and simply drag them into another Package, so I guess the degree of tedium there depends on how fiddly it would be to select those 1000 elements in groups or blocks.

As the song goes: "Tell me more, tell me more..."
Best Regards, Roy

motivatedgorilla

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: How do I move multiple elements across package
« Reply #2 on: February 12, 2014, 02:51:56 pm »
Hi Roy,

The elements aren't in the wrong packages. These were imported using the CSV import feature and were placed in a placeholder package until more information could be specified about them. I am aware I can select multiple elements but seeing I need to select 1000 elements out of over 10,000 elements, you can imagine the attempt to select them and then moving them.

The reason they need to be moved is because as more information is specified about them, they need to go into their respective packages e.g. servers, desktops, operating systems, components, etc.

Let me know if you more information
« Last Edit: February 12, 2014, 02:54:29 pm by motivatedgorilla »

RoyC

  • EA Administrator
  • EA Practitioner
  • *****
  • Posts: 1297
  • Karma: +21/-4
  • Read The Help!
    • View Profile
Re: How do I move multiple elements across package
« Reply #3 on: February 12, 2014, 03:09:36 pm »
Well, that all makes sense.

Would this work? Run a list tool such as a Model View or SQL Query on the CSV target Package to filter for the elements to go in Package A, select all, copy to clipboard, then right-click on Package A and use the Paste Element(s) from Clipboard option?

I'd guess that depends on how finely distinct the elements need to be, and how many Packages and subPackages you need to divide them between.
Best Regards, Roy

motivatedgorilla

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: How do I move multiple elements across package
« Reply #4 on: February 12, 2014, 03:14:43 pm »
That could work. What do you mean by Run a list tool such as a Model View or SQL Query on the CSV target Package? Secondly if i copy and paste them, won't i be creating duplicates?

RoyC

  • EA Administrator
  • EA Practitioner
  • *****
  • Posts: 1297
  • Karma: +21/-4
  • Read The Help!
    • View Profile
Re: How do I move multiple elements across package
« Reply #5 on: February 12, 2014, 03:50:34 pm »
Well, I forgot to recommend that you had the CSV Package in a different Project file. However... even though I tried a couple of tricks along the way, unfortunately, the final paste wouldn't come out right. Forget I spoke!  

My colleagues recommend that you use a script. SO much easier. And if you ask nicely...
Best Regards, Roy

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: How do I move multiple elements across package
« Reply #6 on: February 12, 2014, 03:53:56 pm »
If you have an SQL query which gives the list of elements you want to move, then the following JScript example should demonstrate a way you can move your elements to a specified package.

This example uses Repository.GetElementSet to get a collection of elements returned by a SQL query (note: the query must return a list of t_object.Object_ID values).  Loop this collection and then set the PackageID to the id of the desired package.  In this example, the elements are moved to the currently selected package in the Project Browser.

Code: [Select]
     var queryResults as EA.Collection;
      var theElement as EA.Element;
      var sql = "<insert sql query here>";
      
      var targetPackageID = Repository.GetTreeSelectedPackage().PackageID;
      
      queryResults = Repository.GetElementSet( sql, 2 );
      
      for ( var i = 0; i < queryResults.Count; i++ )
      {
            theElement = queryResults.GetAt(i);
            theElement.PackageID = targetPackageID;
            theElement.Update();
      }

motivatedgorilla

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: How do I move multiple elements across package
« Reply #7 on: February 13, 2014, 05:21:52 am »
Awesome. Thanks Aaron & Roy. I'll give it a whirl