I am creating a script to change the material property of an element to match the highest density of nearby elements. The goal is to generate a list of elements and a list of material properties to assign my density to. The material properties are already named in the order by how dense it is. Therefore, it's the reason why it's compared. However, this script is slow in the context of having tens of thousands of elements. Is there any way to speed this script up? I was thinking multithreading or a faster function that I haven't been able to find.
*createmark sets 1 "Eset_Surface" *isolateonlyentitybymark 1 *createmark elems 1 "displayed" set surfaceElements [hm_getmark elems 1] set densityList [] foreach e $surfaceElements { *clearmarkall 1 *clearmarkall 2 *createmark elems 1 "by id" $e hm_getnearbyentities inputentitytype=elems inputentitymark=1 outputentitytypes={elems} outputentitymark=2 radius=0.9 nearby_search_method=sphere set nearbyElements [hm_getmark elems 2] set densityElement 1000 foreach n $nearbyElements { set materialID [hm_getvalue elems id=$n dataname=material] if {$materialID < $densityElement} { set densityElement $materialID } } lappend densityList $densityElement } llength $densityElement