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
  unable to remove all elements from list based on a condition sg_python 3 371 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  How to remove some elements from an array in python? gohanhango 9 980 Nov-28-2023, 08:35 AM
Last Post: Gribouillis
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 426 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Checking if a string contains all or any elements of a list k1llcod3 1 1,023 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  Summing up set elements(HH:MM:SS) tester_V 4 1,102 Dec-22-2022, 10:03 AM
Last Post: perfringo
  How to change the datatype of list elements? mHosseinDS86 9 1,896 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 1,505 May-27-2022, 09:09 AM
Last Post: paul18fr
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,011 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 1,744 May-13-2022, 06:06 PM
Last Post: deanhystad
Question Change elements of array based on position of input data Cola_Reb 6 2,061 May-13-2022, 12:57 PM
Last Post: Cola_Reb

Forum Jump:

User Panel Messages

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