I guess I was right XD
I did the testing you should have done but I did it because I'm new at this too so I didn't know either.
When you don't know, just test stuff, it's fun, and let the others know of your results =D
I used this simple code while creating lines at the same position (and length) to check for their ObjectId and Handle.
[CommandMethod("test1")]
public void Test1() // This method can have any name
{
Document newDocument = Application.DocumentManager.MdiActiveDocument;
Editor newEditor = newDocument.Editor;
PromptSelectionOptions pSO = new PromptSelectionOptions();
pSO.AllowDuplicates = false;
SelectionSet sS = newEditor.GetSelection(pSO).Value;
using (Transaction newT = newDocument.TransactionManager.StartTransaction())
{
foreach (SelectedObject item in sS)
{
ObjectId thisObjectId = item.ObjectId;
Handle thisHandle = item.ObjectId.Handle;
}
}
}I created 5 lines and these were the results:
Line 1 - OID: 8796087802544 Handle: 223
Line 2 - OID: 8796087802592 Handle: 226
Line 3 - OID: 8796087802608 Handle: 227
Line 4 - OID: 8796087802688 Handle: 22C
Line 5 - OID: 8796087802704 Handle: 22D
I created them exactly one after the other, yet, you see a jump in the Handle number from Line1 to Line2 (223 to 226). Why?
Well, the truth is that after I created Line1, I created two other lines with the wrong dimensions and positions. AutoCAD gave them Handles 224 and 225 but after deleting them AutoCAD did not update the Handle seed (back to 224 for the next object to be created).
--I think AutoCAD never updates the seed, which might be the best thing to do. You can update the seed manually but I don't see a use for it. I think it's best letting AutoCAD handle that.--
This is why, when I created Line2, I got a handle of 226.
I created Line3 right after Line2 and so Handle numbers are consecutive, 226, 227.
I did nothing fancy after creating Line3, yet when I created Line4 I got a Handle of 22C (Handles seem to be hexadecimal in base). My guess here is that AutoCAD created some objects in the background and assigned them the handle number not accounted for. This should be no concern because said object will never be part of a selection and your handle number skipping is no problem.
Line 5 was created normally, no surprises there.
The selection is done by the Handle number, from highest to the lowest.
Everytime I would make a selection, the latest created object(line) would be the first in the SelectionSet. That is because the latest created object has the highest handle number.
Even after I scattered the lines, the last line I created (Line2 when I had 2 lines, Line3 when I had 3 lines, Line4 when I had 4 lines and Line 5 when I had 5 lines), the one with the highest handle number would appear at the top of the SelectionSet.
That is why, if you create objects and them move them around, the SelectionSet won't have them in the order you are seeing them. But there may be a workaround if you are copy items from another drawing because in that case AutoCAD is then assigning new handles to each new object being pasted on the drawing.
Can you test this?
-Create object in a drawing, deleted, delete, deleted, create, created, delete, paste a lot, delete, paste a lot, delete, paste, etc.etc. etc. you're doing this to get handle numbers. when you're deleting objects, the next one you create should not be consecutive to the last one you created and still have on your drawing.
-End up with a few objects, about 10? pick them randomly and then paste them to a new drawing.
-Use my code snippet to check for handle numbers (use a breakpoint, of course, or add a few lines to print them on command line). Are they consecutive?
My guess is that they are indeed consecutive.
Awaiting your results