Revit API Selected Element Set order

Revit API Selected Element Set order

jdkirk5
Participant Participant
4,634 Views
6 Replies
Message 1 of 7

Revit API Selected Element Set order

jdkirk5
Participant
Participant

I am trying to create a very simple addin for Revit that numbers duct in a new shared parameter. The issue that I have is that the duct that I select is numbered according to the order that it is drawn in. I would prefer it to be numbered in the order of the run rather. My question is does anyone know what property of the duct is used to establish the order that objects are placed in and called out of a SelElementSet? And can this be changed or can the order in a SelElementSet be changed according to another parameter?

Thanks

0 Likes
4,635 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

Dear Jdirk5,

 

As far as I know, the SelElementSet is a set and thus unordered.

 

If you wish to keep track of the order in which a user interactively selects elements, you will probably have to use PickObject, ask them to be selected one by one, and keep track of the selection order yourself.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 7

jdkirk5
Participant
Participant

Jeremy,

 

Thanks for the suggestion. I'll give PickObject a try, though I fear it will make the process a little tedious with lots of objects.

As far as I can tell the numbers are assigned to the objects in the order in which they were drawn so I may see if I can iterate through and pick the object by another parameter.

 

Thanks again

 

Jason 

0 Likes
Message 4 of 7

jeremytammik
Autodesk
Autodesk

Dear Jason,

 

Thank you for your appreciation.

 

Yes, indeed, the integer values of the element ids are normally growing in the same order the elements were added to the database.

 

This is undocumented and unsupported behaviour, however, and may change at any time with no warning.

 

At the moment you could gernerally (? or mostly, or often?) use that to sort the elements in the order they were added to the database, though.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 7

Anonymous
Not applicable

Oops wrong account

0 Likes
Message 6 of 7

Troy_Gates
Advocate
Advocate

This is how I have users pick in a certain order and adds the elements to a list in that order...

 

List<ElementId> elementIds = new List<ElementId>();
bool flag = true;

while (flag)
{
	try
	{
		Reference reference = uidoc.Selection.PickObject(ObjectType.Element, selFilter, "Pick elements in the desired order and hit ESC to stop picking.");
		elementIds.Add(reference.ElementId);
	}
	catch
	{
		flag = false;
	}
}

 

Message 7 of 7

jdkirk5
Participant
Participant

Thanks Troy,

 

 

I ended up using the PickObject and it seems to work great. Ideally I would have liked for my entire selection to be numbered without having to pick each piece individually as this would have been quicker, but I realise that there are sometimes complications with the ordering that require user input.

 

Jason Kirk

0 Likes