Sort coordinates by parameter

So I have this list of coordinates that I want to sort by a length parameter. Thought it was simple, but I’m stuck.

Its connector points from a duct fitting, and this fitting has 2 parameters: B1_Def and B2_Def, which is the width of the duct fitting in each end. I want to sort each sublists so the connector point on B1_Def is always first.

Any help?


XX2

Try using the Point.X , Point.Y and Point.Z nodes

How would that be an advantage? I just need to sort the coordinates, and I need X, Y and Z in one list. If I use Point.X, Point.Y and Point.Z it will split them into 3 lists?

I think you need to know the 2 points of placement left to right or right to left?
btw. the search button might help you also
image

Yes correct. I already extracted the x.points later in the script, so I know the difference between the 2 x points.

But in order to get the correct result (+ vs -) I first need to sort the coordinates (all the points - not just the x. point) so that the B1_Def side always is first.

I tried the search button before creating this topic - I didn’t find a solution :wink:

So, if you have the points 1 and 2, draw a virtual (dynamo geometry) line between the points and use the Line.Direction node
would that help?

This really depends on how your family is built, but… My belief is that the info you seek can be found with a combination of the two points and the directions. Let’s say P1 is an input and P2 is the output.

Worst case, assuming the directions are vectors, it could be done like this:
T* ake the distance between the two points

  • Divide that distance by two.
  • Translate the first point by that distance along the associated direction.
  • Get the distance from the translated point and point two.
  • If it now less than the divided distance return 0, otherwise return 1.
  • Use a List.ShiftIndicies to move the point Paris by those values. Your points should now be in ‘input-output’ sequence.

If the directions are a value like ‘in’ or ‘out’ you can use a List.SortByKey node and be completely finished.

No matter what that value is, watch your list levels and lacing carefully.

1 Like

@Marcel_Rijsmus This will just give me the difference between the points, right? I already got those, so my question is how to sort my list by a parameter.

Or am I missing something?

@JacobSmall Thanks for your reply.

Unfortunately I can’t use the directions because they switch around every time I run the script even though I dind’t change the family. So I need to sort the list before subtracting the points - otherwise my numbers will be unconsistent.

Do you know if it is possible to use List.SortByKey to sort by my B1_Def parameter?

That doesn’t make much sense to me… are you sure the order of points doesn’t also change on each run?

Can you provide your dyn and a sample model with say nothing but 8 connectors and the associated ducts? Purge unused a few times to be sure that everything is cleared out.

1 Like

Hi @Mxxx ,

Wouldnt this simple solution not work? (Check my list lacing in the second pic)

If not, could you maybe explain again how your B1/B2 parameter values compare to your points? Is the B1 point always higher (Z-value)? How do you want to sort them.

See below:

Kind regards,
Daan

PS: if you want to sort your points by your B1_Def and B2_Def parameter values, use the node Parameter.ValueByName node twice and use the node list.combine with a list.join node as combinatior for your keys input.

Yes, the order changes. But that is what I do not want them to :slight_smile: I want the order to be the same always. It doesn’t really matter if it is the B1 point or the B2 point that comes first, but somehow I need to sort them.

Hi @Daan

Thank you for your post! I tried your two first suggestions, but the order of the points still switch around.

It’ not really the value of the B1/B2 parameter I want to sort by. I want dynamo to recognize which side the point is located in - is it located in the side of B1 or the side of B2? And then all points located in the B1 side has to be first in order. Does it make sense?

Can you post a sample rvt with say 15 connections and no other content (Deere all views but one 3D view, delete all other model elements, and pure all unused), and your current Dynamo graph?

So I found a solution myself :slight_smile:

1 Like