Closed enzyme69 closed 6 years ago
As a result the list is back to original sorting.
Object ID Sorting can probably do the job as well with custom index value, but that is for future user to figure out themselves.
Basically what I am doing:
Oh yeah btw I tried using Exec Mod Node, but I cannot "import re" for that node. Not sure why. @Kosvor2
but you already can sort by object's index (using object['idx']
as key ) --- If the objects are generated by a Sverchok Object node (like BMviewer etc...)
in ExecNodeMod. just this one line.
extend(list(sorted(V1, key=lambda obj: obj['idx'])))
NameError: name 're' is not defined
we can/should fix that. It's a matter of adding locals()
to the exec( )
context. Similar to this change
in ExecNodeMod, you can do this too:
def natural_sort(obj):
import re
return int(re.search('\d+', obj.name).group())
extend(sorted(V1, key=natural_sort))
see
we can change it to
- exec('\n'.join([j.line for j in self.dynamic_strings]))
+ exec('\n'.join([j.line for j in self.dynamic_strings]), locals())
and imports will work (in main body of the lines of text).
i've just updated Sverchok. you can now write
from re import search
natural_sort = lambda obj: int(search('\d+', obj.name).group())
extend(sorted(V1, key=natural_sort))
in ExecNode Mod.
lovely!
Once again I encountered a situation where Object sorting become an issue because of no padding on the names. Usually after using Viewer BMesh node and then using Objects In node to get the objects back, the list sorting become a bit wrong.
So I created a bridge that sort the object by natural sorting.
SN LITE as below: