# python | |
# | |
# Author: Jeff LeRoy (extol) www.leroyfx.com | |
# | |
# Ex_Select_Visible_Meshes.py v1.3 | |
# | |
#------------------------------------------------------------------------------------------------ | |
#--TO_USE----------------------------------------------------------------------------------------- | |
# | |
# The purpose of this mesh is to select the visible meshes in the scene (main or bg). if you use | |
# the arg "selectmeshes" it will select all meshes in the scene wether they are hidden or not | |
# | |
#------------------------------------------------------------------------------------------------ | |
#--TO_DO----------------------------------------------------------------------------------------- | |
# | |
# | |
#------------------------------------------------------------------------------------------------ | |
#--VAR------------------------------------------------------------------------------------------- | |
num_Layers = lx.eval ('query layerservice layer.N ? all') #get number of mesh layers | |
L_Layers = lx.eval ('query layerservice layers ?') #get list of all mesh layers | |
L_visibleLayers = []#list of layers to select | |
args = lx.arg() | |
selMode = lx.eval ('query layerservice selmode ?')#get current selection mode | |
highlightedMeshes = lx.eval ('query sceneservice selection ? mesh')#get the name of mesh layers that are highlighted | |
#------------------------------------------------------------------------------------------------ | |
#--CODE------------------------------------------------------------------------------------------ | |
if num_Layers > 1: | |
sel_meshType = type(highlightedMeshes) | |
lx.eval ('select.drop item') #drop selection | |
def selectAll(): | |
for i in L_Layers: | |
lx.eval ('select.layer %s add' % i) | |
def selectAllVisible(): | |
#--------------Checking for current mesh selection and adding it to the selection list | |
#--------------(if a mesh layer is highlighted but the visibility "eye" is not on) | |
if sel_meshType is str:#only one mesh item is selected | |
highlightedIndex = lx.eval ('query layerservice layer.index ? %s' % highlightedMeshes)#get the index of the mesh that is highlighted | |
L_visibleLayers.append (highlightedIndex)#add that mesh to the select list | |
elif sel_meshType is tuple:#sel_meshType not a string so multiple meshes must be selected | |
for i in highlightedMeshes:#For every mesh in highlighted list | |
highlightedIndex = lx.eval ('query layerservice layer.index ? %s' % i)#get the index of the meshes that are highlighted | |
L_visibleLayers.append (highlightedIndex)#add that mesh to the select list | |
#--------------Adding all layers with visibility "eye" on to the selection list | |
for i in L_Layers: | |
visibility = lx.eval('query layerservice layer.visible ? %s' % i)#get the visibility of the mesh (main,fg,bg,none) | |
if visibility != "none" and i not in L_visibleLayers:#if layer is "bg" "main" or "fg" and not already in the select list | |
L_visibleLayers.append (i)#add it to the select list | |
#--------------Select all the mesh layers in the selection list | |
for i in L_visibleLayers:#for every mesh in list | |
lx.eval ('select.layer %s add' % i)#select that mesh | |
if args == "selectmeshes": | |
selectAll() | |
else: | |
selectAllVisible() | |
lx.eval ('select.typeFrom %s' % selMode) #restore selection mode | |
#------------------------------------------------------------------------------------------------ | |
#--UPDATES--------------------------------------------------------------------------------------- | |
# v1.3 | |
# added code to select highlighted meshes that dont have the visibility "eye" turned on | |
# v1.2 | |
# fixed code so it doesnt ignore layers that are in the fg. it also drops selction first incase | |
# a camera or something is selected. | |
# v1.1 | |
# Added the argument selectAllVisible so it will only select mesh that are visible in the viewport | |
#------------------------------------------------------------------------------------------------ | |
#------------------------------------------------------------------------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment