.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

determine the order of selected objects when I selected

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
ditran7577
780 Views, 8 Replies

determine the order of selected objects when I selected

Hi Pro,

 

Please let me know how to determine the order of objects selected (i.e text, block reference...).according to type or X, Y ..?

 

Thanks,

8 REPLIES 8
Message 2 of 9

Please explain in detail what you need to determine. Give an example of code that you want to make changes.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 9
ditran7577
in reply to: ditran7577

I have many object located everywhere. I selected them in one windown. I want to know the rules of Autocad in selectionset. For example, I have some blocks in same position and som other blocks located in model space everywhere. I don not know the order of selected objects when I selected them.

Message 4 of 9


@ditran7577 wrote:

I have many object located everywhere. I selected them in one windown. I want to know the rules of Autocad in selectionset. For example, I have some blocks in same position and som other blocks located in model space everywhere. I don not know the order of selected objects when I selected them.


It depends on what you mean by 'order'.  

 

Do you mean the order in which the objects were created? If not, then what 'order' are you referring to?  If multiple objects are selected using a single Window/Crossing selection, they were all selected in the same step, and you can't distinguish the order in which the objects were selected because they were all selected in one step.

 

If you need an ordered selection, you have to require each object to be picked in the desired order, you can't accept a Window or Crossing selection.

 

 

 

Message 5 of 9

You can try to analyze how entities was selected (with Window or CrossingWindow) such as:

Get direction of window selection

You can extend this sample as you need.

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 9

May be you misunderstand my mean.

I have an example (attachment). I want to know the order of selection so that I can get exactly value of each position base on their layer. (i.e  Postion(70.4598,33.3311,0.0000) ; level1=1.1;leve2=22)

Thanks,

Message 7 of 9
DouceDeux
in reply to: ditran7577

Hello,

 

I just dealt with a problem that required the analysis of this, the selection order, in the solution.

There must be peole that have experimented a little more than I did but the experimentation I did was enough to gather conclusions and get to a solution.
I needed the user to make 2 windo/cross-selections (I call them drag selecctions XD).

Here's what I found:

 

The first selection had Text and RotatedDimension that were not created in the same order, the were edited as the user saw fit, created, deleted lines or dimensions. The fact that they were either Line or RotatedDimension did not affect their order in the SelectionSet but what seemed to be their creation order (Maybe their handle number, that is what I didn't check for - Reference for handles: http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=18216579) because their selection order would be the same every time.

So I would end up with with a pretty messed up selection order in my SelectionSet, I would try to make some sense of it but to no avail. Text where anywhere they pleased, same with RotatedDimension, and I'm talking about their order, what should be the first selected item was in the middle, the right-most Text was the first selected, etc etc.

I was not gonna get anything programmatic out of this. So I decided not to do it this way for the first selection. I had to go through the textString of the Text and the dimensionText (the properties I wanted) of the RotatedDimension to check if they were what I wanted.

 

For the second selection, they were all texts, because, as with the first selection, I used a SelectionFilter but only for Text.

For the first selection I used a SelectionFIlter for Text and RotatedDimension.

These Text(s) were all nicely packed and in what I would consider a 'correct' selection order because there were all texts imported from Excel. There were created in one operation one right after the other so it would just make sense they had consecutive handle numbers (if this is how they are added to the SelectionSet) thus making for a neat selection order. I just had to go from one to the next and check for what I wanted, not worrying the next text I would go to would not be visually after the previous one.

For what I wanted was to get a code such as "F342".

Then, after getting said code, I needed to get an integer in a different Text, but there was no relation between the number of texts between the text that had the "F342" code and the interger I wanted so I had to check for the text that was after the integer I wanted, which always had the same pattern, but I could do that only because the selection order was neat and not as the first selection.


Just remember that what one would think should be the first selected item in a drag/window/cross-selecction is in fact the last one and the last one is the first to show in the array of ObjectId. I'm guessing the AutoCAD creates a stack of selected objects and when it pukes it out it comes out like that into the SelectionSet. Smiley LOL

Do a decreasing for(){} and you're good to go:

ObjectId[] mySelection = SelectionSet.GetObjectIds();
for(int i = mySelection.GetLength(0) - 1; i >= 0; i--)
{
  //Do fun stuff here
}


Let me know if I helped or I need to read more and improve my grammar >.< (really, tell me ^^)

Tags (1)
Message 8 of 9
ditran7577
in reply to: ditran7577

Thank DouceDeux,

 

You helped me understand more. When I selected all of them by one window, Are the IDs of blocks which same position

consecutive ?

 If they are not arrange, we have to take a bit of time with many object. My calculator will be slow if we use this method.

ObjectId[] mySelection = SelectionSet.GetObjectIds();

for(int i = mySelection.GetLength(0) - 1; i >= 0; i--)

{

//Do fun stuff here

}

Thanks,

Message 9 of 9
DouceDeux
in reply to: ditran7577

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost