Book a Demo

Author Topic: Get the index of the item (package, element . . .)  (Read 6871 times)

ALL_IN_ONE

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Get the index of the item (package, element . . .)
« on: June 04, 2010, 01:11:08 pm »
Hello all,

I would like to delete the modal projekt items. For example I have the id of method and to delete that method I need the index of the method. thus what I do : I iterate like shown below
int methodIDTobedel = 5468;
for(short index = 0, index < elemObjeckt.Methods.count;index++)
{
      EA.Method methodObj = elemObjeckt.Methods.GetAt(i) as EA.Method;
      if(methodObj.MethoID == methodIDTobedel )
     {
         elemObjeckt.Methods.DeleteAt(index ,FALSE);
         break;
      }
}

From the above code I have to iterate through all the methods and only one of them will be true.

Thus my question is if I have the ID of the method to be deleted can I also get the index of the method with the help of id. This will reduce unnecesary time of iteration.

*** I also tried  elemObjeckt.Methods.GetByName(string name) . .. but we have methods with the same name tooooo .. i think its not reliable . .


Regards,
ALL_IN_ONE

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Get the index of the item (package, element .
« Reply #1 on: June 04, 2010, 03:42:08 pm »
All_In_One

I think that is indeed the only way to delete an item. (unfortunately).
If there is a better way I'd love to know (since my code looks exactly the same as yours)

Geert

ALL_IN_ONE

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: Get the index of the item (package, element .
« Reply #2 on: June 04, 2010, 04:32:18 pm »
Hello Geert,

Thanx for your reply.

Hmmm . . . .may be I will requst sparx to look for an optimize way to delete an item rather than using the index . . . .

Or may be there should be an additional method like
int GetMethodIndex(int MethodID)

But I also believe the index of the operation will not remain the same once they are deleted and refreshed. Thus after the refresh the remaining methods will have a new index.

Regards,
ALL_N_ONE

mrf

  • EA User
  • **
  • Posts: 311
  • Karma: +0/-0
    • View Profile
Re: Get the index of the item (package, element .
« Reply #3 on: June 04, 2010, 04:42:06 pm »
This is completely untested (its getting towards the end of the day, so I'll try and test it tommorow), BUT:

You could possibly use Repository.GetElementSet() to get a collection that contains only the elements that you want to delete, and then delete them.

Disclaimer: May or may not work  8-)
Best Regards,

Michael

[email protected]
"It is more complicated than you think." - RFC 1925, Section 2.8

mrf

  • EA User
  • **
  • Posts: 311
  • Karma: +0/-0
    • View Profile
Re: Get the index of the item (package, element .
« Reply #4 on: June 04, 2010, 04:45:02 pm »
Actually it won't work because you're after methods not elements :(
Best Regards,

Michael

[email protected]
"It is more complicated than you think." - RFC 1925, Section 2.8

ALL_IN_ONE

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: Get the index of the item (package, element .
« Reply #5 on: June 04, 2010, 04:57:21 pm »
Hello MRF,

It would be great if we have for all the below ones . . .

The future method  :)     ::)
GetObjectSet(ObjectType,string IDList,long Options)

it should cover any type of object covered in EA otProject
otElement, otClient, otPAckage, otDatatype, otConnector . . . . . and so on

@Geert : What do you think about  it


Regards,
ALl_IN_ONE

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Get the index of the item (package, element .
« Reply #6 on: June 04, 2010, 05:08:24 pm »
If you are sending a request, then I would rather ask for a Delete() method on all classes that have an Update() method.

Wouldn't that be a lot easier?

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Get the index of the item (package, element .
« Reply #7 on: June 04, 2010, 05:09:35 pm »
Quote
The future method  :)     ::)
GetObjectSet(ObjectType,string IDList,long Options)

And this is also a very good idea (but a different request)

Geert

ALL_IN_ONE

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: Get the index of the item (package, element .
« Reply #8 on: June 04, 2010, 05:30:59 pm »
Hello

yes having an upadate option within the Delete() is good . . .

but I am not sure how that will reduce the time in processing . . . .

Newaz in the meant time I will send them the request for

1) int GetObjectIndex(EA.ObjectType ObjectType, int objectID);
2) GetObjectSet( EA.ObjectType ObjectType,string IDList,long Options);
3) bool DeleteFor(int[] index, bool Refresh);

hope te above ones help others toooo . . . ::)

Regards,
ALL_IN_ONE

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Get the index of the item (package, element .
« Reply #9 on: June 04, 2010, 05:35:55 pm »
It will reduce time in processing because then you can do:
Code: [Select]
EA.Method methodObj = GetMethodByID(methodIDTobedel);
methodObj.Delete();

So no more need to iterate anything, and you don't even have to get the containing Element.

Geert

ALL_IN_ONE

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: Get the index of the item (package, element .
« Reply #10 on: June 04, 2010, 05:45:09 pm »
Hello

oh ok . . now in got your point . .

I think this is really good, short and simple  . . .

Regards,
All_IN_ONE