Python Forum

Full Version: Sorting Elements via parameters pointing to those elements.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am looking for an algorithm or sorting code that does not use function calls such as numpy or scipy. I am working with IronPython in Revit to sort contiguous elements so I cannot make calls to CPython functions. Each contiguous element is numbered, but not consecutively, but each element has two parameters that point to the element next to it. Lets say the parameters are called Point1 and Point2 and the elements are numbered 1-5.

When I sort by element number I get the following:

Point1 Point2 > 0 5,6 4,5 4,2 3,1 3
Element# > 1,2,3,4,5

Where Element# 1 has Point1 = 0 and Point2 = 5, Element# 2 has Point1 = 6 and Point2 = 4, etc.

But this does not represent the actual order of elements.

The actual order looks like the following:

Point1 Point2 > 0 5,1 3,5 4,2 3,6 4
Element # > 1,5,3,4,2

Element 1 is connected to element 5 is connected to element 3, etc., and Point1 and Point2 of each element# indicate what is connected to each side. Realize Point1 does not always show what element is on the left and point2 does not always show what is on the right, they can be reversed. The Point1 values of 0 and 6 indicate element#'s not show to the far left and right. The values of 0 and 6 could be anything other than 1-5 and that is determined by Revit. It is the relationship between the Point1 and Point2 values and the element# that matters. The element numbering and parameter values are determined by Revit which I have no control over, this is why I need to sort element#'s by using the Point parameter values. I am not a great programmer, please have mercy on me.
please show code for what you have tried.
(Jan-05-2021, 08:06 PM)Larz60+ Wrote: [ -> ]please show code for what you have tried.

I have only tried a solution in Dynamo before realizing I would need to do recursive in Python to accomplish my goals. I did not attempt any Python code as I am not a good programmer. If you have am idea of the generic looping algorithm I can adapt it.
I was able to accomplish my goal using Dynamo and a little bit of Design Script. I do not see how to post jpg of my solution here. Thanks for the help.