hi everyone, I’m trying to use set parameter by name for some structural beams,
but after I sorted them natural using (List SortNatural Node), I got list of strings, I need to know how to convert them back to list of elements with the same sorting, so I can use them.
thank you in advanced
Hola Amiga @janbarsoum try List.IndexOf and then List.GetItemAtindex to retrieve your original items in the new order, I hope this can help you!!
https://dictionary.dynamobim.com/#/BuiltIn/Action/IndexOf
1 Like
Hi @janbarsoum
It seems to function.
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
elements = IN[0]
import re
def natural_sort(l):
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key.Name)]
return sorted(l, key = alphanum_key)
OUT = natural_sort(elements)
3 Likes
It works, Thank you so much
1 Like