Python Forum
Sorting Elements via parameters pointing to those elements.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting Elements via parameters pointing to those elements.
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.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Add elements to a Dictionary muzikman 12 658 Sep-10-2021, 03:17 PM
Last Post: muzikman
  Why am I getting list elements < 0 ? Mark17 8 622 Aug-26-2021, 09:31 AM
Last Post: naughtyCat
  Looping through nested elements and updating the original list Alex_James 3 362 Aug-19-2021, 12:05 PM
Last Post: Alex_James
  Extracting Elements From A Website List knight2000 2 473 Jul-20-2021, 10:38 AM
Last Post: knight2000
  Make Groups with the List Elements quest 2 488 Jul-11-2021, 09:58 AM
Last Post: perfringo
  Matching two files based on a spited elements tester_V 5 711 May-30-2021, 07:49 PM
Last Post: tester_V
  I cannot delete and the elements from the list quest 4 936 May-11-2021, 12:01 PM
Last Post: perfringo
  List of lists - merge sublists with common elements medatib531 1 995 May-09-2021, 07:49 AM
Last Post: Gribouillis
  Testing Split elements tester_V 4 760 May-08-2021, 10:54 PM
Last Post: snippsat
  Take first Elements of sublists quest 2 607 Apr-26-2021, 11:32 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020