Sorting Sublist By items inside Sublist

I am trying to make a tool that compare’s items inside of solids with each other. So the tool has to sort the sublist by items inside the sublist. this is what i have now but it doesnt work i also tried to use keys but i do not understand how that works. this is what i have now:
image
What the logic should look like:

I know this should be not that hard but i looked at so many things and still dont know how to do it.

Probably better ways but id sort the lists then concatenate the items together as strings, then use those as keys for grouping.

1 Like

I think you are trying to group all the sublists by the first item in them, and sort the groups by their common first item.

  1. List.FirstItem to get the initial keys.
  2. List.GroupByKey to group the lists (@L3 might be required here) by the keys found in step 1.
  3. ListSortByKey to sort the resulting groups by their respective keys (the two nodes fit very nicely right next to each other).

it works but it will only check if the key value of the first item in the sublist is the same and not if the rest of the items in the sublist are the same and have the same amount of items right?

the problem is that it only works with sorting by the first item in the sublist and not with all the items in the sublist:

Right. If you want the full list to be what drives it you will need to either convert your data to something comparable (i.e the XYZ values of a point concatenated into a single string) or live with the accuracy which String.FromArray or String.FromObject + concatenation provide. The resulting string representation becomes your keys.

So if you want to use String.FromArray replace the List.FirstItem with that node and you should be all set - just watch your list levels.

I feel like i have tried every level by now with stringFromArray and i still do not get it to work. It will only make keys and groups if i put my list on L4 and sortbykey also does not work rn.

This is my original concept but coded out, assume this is what you’re after…

|

You could make a range of same length, index that, then feed to getitematindex as well if you want to group/sort original lists in the same manner as their original key.

1 Like

This is what i am looking for but i have a problem; 2 elements inside of the list are Null in string.Concat these are a line and a solid. i need these 2 dynamo element’s later in the script (they have to get sorted with the rest and are for making scopeboxes with for 3d views and 3d revit lines with that show on drawing) i have a script that takes the sorted lines and make’s for evert type a new line type so u can detect it in a drawing. is there any way around it?

This is the working code without the nulls:
image

This is the code breaking with nulls:

Your list structure appears to be more complex than your initial example. We will need a sample model and script to see what you’re working with I think.

How are you generating the strings? Note that a string representation of a cuboid can be “solid”, and that a string representation of a sphere can be “solid” so your goal might not be attainable.

I have a sneaking suspicion that a dictionary or another method of object management might be better suited.

1 Like

Do you also wanna know there is a Solid or Line in the Solid?
Or just the other Elements like the bakstenen and hout?

no i also need the line and the solid i use the solid to get item at index 0 and make scope boxes in revit for views with them and i use the line’s for placing specific line’s on the revit drawing

i got it to work with solids and had to make my line’s a ModelCurve now they get sorted with the rest of the materials.

The problem I see is that if the solids are not the same you’ll be in trouble.

Rectangle.ByWidthLength(1,1).ExtrudAsSolid(1) + “”; returns “solid”, and Circle.ByCenterPoint.Radius(Point.Origin(),1).ExtrudeAsSolid(1) + “”; also returns “solid”. As a result if the four other keys all match these will be grouped together even though they are different.

If there is any chance this could happen with all the datasets you could ever process, then you need to come up with a new approach.

What is it you are trying to do in the ‘big picture’ sense?

What is the purpose of your graph?

this is what i am trying to do:

  1. I am making solid boxes on the side’s of elements. (already have a good working script for that)

  2. I compare the elements inside the boxes to compare if the connection points are the same or if it has a other type of connection. (already have a script working but it does not infinit scale only by making spaghetti code this code does not work with keys but with string.contains and list count to determine if the connection is the same:

  3. Lines beacome modelcurve with their own name and are visible on drawing so u know where connection is (so that is y i need them to be sorted)
    Boxes i take the first box of every list of list and it for making 3d viewboxes and 2d sections after that they i create a sheet with those 2 views

i am just trying to clean up my code a bit. and making it so i dont have to manualy scale it like the old code (this is the old code)