Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# python
#
# Author: Jeff LeRoy (extol) www.leroyfx.com
#
# Ex_Select_Connected_Weighted.py v1.2
#
#------------------------------------------------------------------------------------------------
#--TO_USE-----------------------------------------------------------------------------------------
#
# To use this script select one edge that has an edge weight then run the script. It will select
# all connected edges that have the same weight value. If you add the argument "any" for the script
# and then run it, it will select all connected edges that have an edge weight whether it is the
# same value as the first edge or not.
#
#------------------------------------------------------------------------------------------------
#--TO_DO-----------------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------------------------
#--VAR-------------------------------------------------------------------------------------------
arg = lx.arg()
L_NewEdges = []
L_WeightedEdges = []
sel_Layer = lx.eval ('query layerservice layer.index ? main')
startEdge = lx.eval ('query layerservice edges ? selected')
num_Edges = lx.eval ('query layerservice edge.N ?')
#------------------------------------------------------------------------------------------------
#--CODE------------------------------------------------------------------------------------------
def Message():
lx.eval ('dialog.open')
lx.eval ('dialog.setup info')
lx.eval ('dialog.title "Ex_Select_Connected_Weighted.py"')
lx.eval ('dialog.msg "Please select ONE edge with an edge weight"')
if num_Edges == 1:
startEdgeWeight = lx.eval ('query layerservice edge.creaseWeight ? %s' % startEdge)
if startEdgeWeight > 0:
L_WeightedEdges.append(startEdge)#add startEdge to list
b = len(L_NewEdges)
a = len(L_WeightedEdges)
#------------------------------------------------------------------------------------------------
while a != b: #while not equal
if b > 0:#if L_NewEdges has indices
for e in L_NewEdges:#for every edge in the list
if e not in L_WeightedEdges:#if its not already in L_WeightedEdges
L_WeightedEdges.append(e)#add it
lx.eval ('select.expand')#grow selection
growSelection = lx.eval ('query layerservice edges ? selected')#get list of selected edges after grow
if arg == "any":
for e in growSelection:#for every edge in the grown selection
growEdgeWeight = lx.eval ('query layerservice edge.creaseWeight ? %s' % e)#get the edge weight value
if growEdgeWeight > 0: #if it has an edge weight
if e not in L_NewEdges:#if its not already in L_NewEdges
L_NewEdges.append(e) #add to L_NewEdges
else:
for e in growSelection:#for every edge in the grown selection
growEdgeWeight = lx.eval ('query layerservice edge.creaseWeight ? %s' % e)#get the edge weight value
if growEdgeWeight > 0 and growEdgeWeight == startEdgeWeight: #if it has an edge weight
if e not in L_NewEdges:#if its not already in L_NewEdges
L_NewEdges.append(e) #add to L_NewEdges
lx.eval ('select.drop edge')
for edge in L_NewEdges:
vertList = lx.eval ('query layerservice edge.vertlist ? %s' % edge)#get edge vertlist
lx.eval ( 'select.element %s edge add index:%s index2:%s' % (sel_Layer, vertList[0], vertList[1]))#select edge
b = len(L_NewEdges)
a = len(L_WeightedEdges)
#------------------------------------------------------------------------------------------------
#found all of the connected edges with weights so drop all edges and select L_WeightedEdges
lx.eval ('select.drop edge')
for edge in L_WeightedEdges:
vertList = lx.eval ('query layerservice edge.vertlist ? %s' % edge)#get edge vertlist
lx.eval ( 'select.element %s edge add index:%s index2:%s' % (sel_Layer, vertList[0], vertList[1]))#select edge
else:#no edges with weights selected
Message()
else:#no edges selected or more than one
Message()
#------------------------------------------------------------------------------------------------
#--UPDATES---------------------------------------------------------------------------------------
# --v1.2
# --Used a different method to select edges, updated lx.arg
# --v1.1
# --Added arguments to select connected edges with same edge weight only or any connected edge with an edge weight
#------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment