Skip to content

Instantly share code, notes, and snippets.

@csprance
Created October 24, 2021 04:49
Show Gist options
  • Save csprance/5d9edb2a6f06407bf470f335573c582d to your computer and use it in GitHub Desktop.
Save csprance/5d9edb2a6f06407bf470f335573c582d to your computer and use it in GitHub Desktop.
A modo script to select verts whose selected weight maps fall within a given range. To use Select a mesh and then select a weight map. Then specify a min and a max value for the range
import lx
import lxu
import modo
import sys
def get_selected_weight_maps():
"""
Get the selected weight maps from the scene
:return: List of selected weight maps
"""
scene = modo.Scene()
vmaps = []
v_map_indices = lx.eval('query layerservice vmaps ? all')
for index in v_map_indices:
vmap_type = lx.eval('query layerservice vmap.type ? %s' % str(index))
vmap_sel = lx.eval('query layerservice vmap.selected ? %s' % str(index))
vmap_name = lx.eval('query layerservice vmap.name ? %s' % str(index))
if vmap_type == 'weight' and vmap_sel:
vmaps.append(vmap_name)
return [
w
for w in sum(
[
list(item.geometry.vmaps.weightMaps)
for item in scene.selectedByType(lx.symbol.sTYPE_MESH)
],
[],
)
if w.name in vmaps
]
def select_by_weight(min_t, max_t):
"""
With a min and max value select all the verts where the weights are within the range
:param min_t: The min value to select
:param max_t: The max value to select
:return: None This function has side effects only of selecting all verts within the range of min_t, max_t
"""
scene = modo.Scene()
# get the selected weights
weights = get_selected_weight_maps()
# for each weight map find all the weights over the threshold
for weight_map in weights:
for vert in weight_map._geometry.vertices:
(weight,) = weight_map[vert.index]
if min_t <= weight <= max_t:
vert.select()
select_by_weight(0.9, 1.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment