# Sorting Elements and Views by level to name in a logical order

Hi, I have a bunch of elevations created on curtain walls. I was naming the views and parameter mark of the curtain wall by the level they were on. That was this whole crazy thing below. It named them with the prefix of the level but in a poor logical order and sometimes put the wrong name to the wrong element. I think this was because of not sorting the lists at the end by the key group at the start.

Anyway. Ultimately my idea to number the curtain walls and views in a logical order on a plan is to group the curtain walls by level, extract each group of curtain walls by level and run their own line through them by their average points on each level. Hopefully this line will run through by the next closest point to it. Then I can use this line to number them as it goes through them. Similar to a door numbering script I have (that numbers doors by closest to a line). Ultimately getting a plan that looks like its numbered curtain walls/windows with some sense.

1. Group the curtain walls by level. My start is below but Iâ€™m not quite sure how to group the elements after?

2. Once Iâ€™ve got those elements grouped, Iâ€™ll try make a line through each grouped element on a level. Something like below. Need to figure out 1 to give this a go properly.

3. Then ill use some other stuff I already have to name it with correct prefixes.

The views for each of the curtain wall elements will be named the same as the curtain wall marks. Iâ€™m wondering if changing the grouping order of the curtain wall elements is going to stuff up the naming of the views.

Sorry if this is too many things in one post. Tried to make the best sense of it I could. Pretty much just need help with grouping 1 if Iâ€™m on the right track. Thanks for any help

The first problem with the sort and group is that you should be feeding the elements into the group by key command, or at least be using another groupbykey with the level.name as the keys to group it.

1 Like

Got 4 different lines to number off. However the line is ugly. All over the show haha. Not sure how I would order the Location points to create a line in a logical sense along the points (from one point to next closest and so on). Would I even need a line if I was ordering the elements by their location somehow

Woo! might be onto something! Seems to make a line with logical sense around things

There was a post earlier this month about renumbering rooms based on the shortest distance to the next room, not sure if it could help you or give you another route (ha) to take.

1 Like

Not sure how I would sort my elements by the new sorted coordinate list. Looking at your suggestion. Not sure how Iâ€™d adapt mine to use your python. Does it take sublists? I would also need to input the first element in each sublist into the Python Script if that makes sense. As im trying to sort the coordinates of each sub list

I can change it to work with sublists and if you want to use the first item in the sublist as the starting point, I can do that too. Post a picture of your list structure and Iâ€™d be happy to help.

so awesome! the list structure is like this if thats what your after. Its elements grouped by levels. Sorry list structure is like below, no level 4

Dynamo 2.0 - vanWallSort.dyn (16.8 KB)

``````# Enable Python support and load DesignScript library
import clr
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
t0 = IN[0] # Wall Elements
t1 = IN[1] # Wall Centerpoints
t2 = []

for _subP,_subC in zip(t1,t0):
_subT = []
t3 = _subP.pop(0)
_subT.append(_subC.pop(0))
while len(_subP) > 0:
t5 = []
for i in _subP:
t5.append(Geometry.DistanceTo(t3, i))
t7 = min(t5)
t8 = t5.index(t7)
_subT.append(_subC.pop(t8))
t3 = _subP.pop(t8)
t2.append(_subT)

OUT = t2
``````

Let me know if this works. It does the same thing as the other thread but goes through sublists like yours. It uses the first wall/point in the sublist as the starting point.

2 Likes

amazing! so incredibly useful. Thank you very much for your time doing that. You wouldnâ€™t happen to know how I sort a list by points? Just encase the other way I was trying would be useful in a certain situation. Feel like Iâ€™ve probably used up all your kindness haha maybe I can find an answer elsewhere

Sorting by points depends on what you are aiming for. You can sort by an X or Y using the same sortbykey method with Point.X or Point.Y. If you want to use an equation for it then it is a different method. You could also sort by distance to a line in a similar fashion.

1 Like

I wouldnâ€™t be able to sort my list of elements by the sort points as perimeter node with dynamo though? would need to go into the line method to do so?

Never heard of sort points as perimeter. What does it do?

Sorts the points around the perimeter of the elements locations. I didnâ€™t really get it till I ran a line through it. Iâ€™ll send you a pic when Iâ€™m back at the office tomrrow

1 Like

Morning Kenny, the sorted new points at the perimeter with a line running through them if what i said didnâ€™t make sense. Its pretty cool

2 Likes

Thatâ€™s great. Does that mean everything works? Also I am curious if the same python would work if you fed in the line geometry instead of point at parameter 0.5.

Everything works with your great python code thanks, your python works with line inputs too! The only thing thats not ideal is the start element it numbers from in the sub-list. Can mess up the logic when it starts numbering slightly. I can maybe figure out a way to organise the sublists to have the closest coordinate to 0,0 at the start or furthest away point. Will figure something out. Thanks for all your help.

Might be able to use your skills on something else. Ill tag you in it if you can be bothered. Its basically mirroring a elevation marker to another side if it finds itself in a solid or area (floor). To keep elevations created on the exterior of the building. Hoping to create a list of the floor surface geometrys minus floors that might be exterior with the name â€śdeckâ€ť or â€śexteriorâ€ť in them

Okay. If you need, I can do the same thing I did in the original where you input a separate list that would have the starting element as the only item in the sublist.

ooooo so then I could work out a way to extract the closest point in each sub list to 0,0 and input that to start? If Iâ€™m on the right track and you dont mind, thatâ€™d be really cool. Maybe let me see if I can figure out how to extract the closest point to 0,0 first in each sub list so you dont waste your time

If you are just looking for the point closest to 0,0 I can do that as well, instead of using a separate input list.

mate, that would be amazing! Iâ€™m just trying to figure out in my mind how the coordinate system works in Revit and dynamo and with rotating true Norths and things. 0,0 could end up anywhere. Iâ€™m assuming it would always be starting at an element furthest from the rest which is fine to start numbering logically. Might be over thinking things haha.