I need to sort the objects in the array by there name without replacing the array with just there names.
The first printed list with all the objects information is what I need, but I need it to be in alphabetical order. The second list is in the correct order but I loose all the objects information.....
arr = selection as array
print arr -- need this array to be sorted by name but still keep all there information
listed = sort(for i in arr collect i.name)
print listed
By
Comments (7)
Comment policy
Thanks Swordslayer
Thank you for clearing that up and making it a lot simpler than I was doing it.
JokerMartini
Just use qsort with a custom function.
best solution for me.... tx
!
Thank you Swordslayer
Sooo clean. Thanks!
Not Updating Variable
I'm not sure why but this is not updating the outer variable MyCustomObjs?????
MyCustomObjs = #()
fn fnAddItmsLst arr = ( -- add Objects to list
userSel = for obj in selection where (classOf obj != XRefObject) collect obj --xref objects don't have controllers
if userSel.count >= 1 do
(
for o in userSel do (appendIfUnique arr o) -- apend new object to array
listed = sort(for i in arr collect i.name) -- local "listed" array is sorted by name
arr = for o in listed collect getnodebyname o exact:true --arr is built using sorted listed array
)
return arr
print arr
)
fnAddItmsLst MyCustomObjs
print "-----"
print MyCustomObjs
This is what I came up with.
Not sure if its the best solution but this is what I came up with.
arr = selection as array
listed = sort(for i in arr collect i.name)
arr = #()
for i=1 to listed.count do
(
newNode = getnodebyname (listed[i] as string) exact:true
appendIfUnique arr newNode
)
clearListener()
print arr