Advertisement
Guest User

Untitled

a guest
Sep 6th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1.  
  2. import rhinoscriptsyntax as rs
  3. import Rhino
  4. import re
  5.  
  6.  
  7. def getLayers(include=False, exclude=False):
  8.    
  9.     """
  10.    Help on function getLayers in module getLayerList:
  11.    
  12.        getLayers(include, exclude)
  13.            Get list of layers that begin with regex L/d.
  14.            Parameters:
  15.                include = List of layers to linclude that do not begin with
  16.                    regex L/d
  17.                exclude = List of layers to exclude from children search
  18.            Returns:
  19.                list of layers
  20.        
  21.    
  22.    """
  23.    
  24.     docLayers = rs.LayerNames()
  25.     layerSplit = [d.split("::") for d in docLayers]
  26.     returnList = []
  27.     nestWarning = 0
  28.    
  29.     # dummy patterns
  30.     includePattern = re.compile(r"______________")
  31.     excludePattern = re.compile(r"______________")
  32.    
  33.    
  34.     if include:
  35.         includePattern = re.compile(r"|".join(include))
  36.     if exclude:
  37.         excludePattern = re.compile(r"|".join(exclude))
  38.     for entry in layerSplit:
  39.         l_i = [i for i, item in enumerate(entry) if (re.search("^L\d", item) or re.search("^P\d", item) or includePattern.search(item))]
  40.  
  41. #       Apply exclude pattern
  42.         exclude = 0
  43.         for item in entry:
  44.             if excludePattern.search(item):
  45.                 exclude = 1
  46.  
  47.         # if the position of the match is at the end of the list, then include it in the return list
  48.         if(len(l_i) > 1) and nestWarning == 0:
  49.             print("Nested L# layers detected. Script will only return layer highest in the heirarchy.")
  50.             nestWarning = 1
  51.         try:            
  52.             if not exclude and (l_i[0] + 1) == len(entry):
  53.                 returnList.append("::".join(entry))
  54.         except:
  55.             pass
  56.     return(returnList)
  57.  
  58. if __name__ == "__main__":
  59.     print(getLayers(exclude=[".3dm", "Make2D"]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement