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.
#1
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.
Reply
#2
please show code for what you have tried.
Reply
#3
(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.
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to change the datatype of list elements? mHosseinDS86 9 485 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  How can I add certain elements in this 2d data structure and calculate a mean TheOddCircle 3 637 May-27-2022, 09:09 AM
Last Post: paul18fr
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 1,328 May-17-2022, 11:38 AM
Last Post: Larz60+
  Replace elements of array with elements from another array based on a third array Cola_Reb 6 581 May-13-2022, 06:06 PM
Last Post: deanhystad
Question Change elements of array based on position of input data Cola_Reb 6 950 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  Creating permutations of N size with no same elements next to one another (recursion) melmoman 1 832 Dec-18-2021, 09:39 PM
Last Post: Larz60+
  Add elements to a Dictionary muzikman 12 2,153 Sep-10-2021, 03:17 PM
Last Post: muzikman
  Why am I getting list elements < 0 ? Mark17 8 1,863 Aug-26-2021, 09:31 AM
Last Post: naughtyCat
  Looping through nested elements and updating the original list Alex_James 3 1,189 Aug-19-2021, 12:05 PM
Last Post: Alex_James
  Extracting Elements From A Website List knight2000 2 1,132 Jul-20-2021, 10:38 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

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