Author Topic: Manipulation of DatabaseServices.ObjectIdCollection - how to add at index?  (Read 2950 times)

0 Members and 1 Guest are viewing this topic.

Proctor

  • Guest
Hello: I have an collection of DatabaseServices.ObjectIdCollection

I would like to re-arrange this collection if i determine that any of the objectids are not in the correct order i need them to be in.

My question is, how can i remove the objectid and then replace the it at the correct index location i want? i know about RemoveAt and I can use this to remove the object; but how do I tell it to add it back at a paticular location?

Thank you,
Proctor

Draftek

  • Guest
Wouldn't if just be easier to create a new collection with the correct order?

Glenn R

  • Guest
I would like to re-arrange this collection if i determine that any of the objectids are not in the correct order i need them to be in.

Seeing as an ObjectID is a 'calculated' property, based off the AutoCAD session ID, drawing and handle, I, for one, would like to see how you determine the 'correct order' of an ObjectIdCollection....?

Proctor

  • Guest
Hi Glen: I don't think i described what I'm doing properly:

My user selects the objects they want. These objects are polygons. For each poly,  i use selectCrossingPoly to give me all the lines that are inside. I set my collection equal to the result set.

After, for each line in the result set,  I do a selectCrossingWindow to find the line that's closest to it and then join them. While doing so, if I do join the line, I want to look in the collection to verify that this line's object id is in between the 2 lines i joined it to. if it's not, i want to move it so that it is.

The reason I want them in this order is because i need to place blocks along each line at a paticular distance (e.g. 2 per ft). in doing so, i may have distance left over from the previous line and if so, i need to calculate that into the distance I need to go along the line it was joined with before placing the next block on the line.

It's hard to explain...so I hope I did ok.
Is it possible for me to manipulate the collection like this?


Maybe I'm going about this the wrong way...and need to try instead to get them into the correct order in the first place as Draftek suggested.

thanks again,
Proctor

sinc

  • Guest
Or just use a generic collection such as List<ObjectId> instead of an ObjectIdCollection.  You can convert the List back into a ObjectIdCollection if you need to pass it into something as that type of argument.

Proctor

  • Guest
That's a good idea....I see that using List(of T) collection has an insert method available and therefore, is much easier to manipulate.

thanks for the idea....

Proctor

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Have a look at this thread http://www.theswamp.org/index.php?topic=19155.0
You too Glenn   :laugh:

I would also consider making an object that implements IComparable that you can sort;

Code: [Select]
struct MyObject : IComparable
 {
  object toSortBy;
  ObjectId id;

  //...
 }
 class MyObjects : List<MyObject>
 {
  ToObjectIdCollection(...)
 }
« Last Edit: September 09, 2009, 10:11:25 PM by Daniel »

Glenn R

  • Guest
heh...I remember that now.