Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. import bpy
  2.  
  3.  
  4. all_collections = []
  5. def get_visible_layer_collections():
  6.    
  7.     def get_all_collections_rec(parent):
  8.  
  9.         for child in parent.children:
  10.            
  11.             global all_collections
  12.  
  13.             if child.visible_get() == True:
  14.  
  15.                 if child.name not in all_collections:
  16.                     all_collections.append(child.name)
  17.             try:
  18.                 get_all_collections_rec(child)
  19.             except:
  20.                 pass
  21.    
  22.     rec_start = bpy.context.view_layer.layer_collection
  23.     get_all_collections_rec(rec_start)
  24.  
  25.     return all_collections
  26.  
  27.  
  28. def hide_view_set_on_visible(unselected):
  29.  
  30.     for vis_collection in get_visible_layer_collections():
  31.         for obj in bpy.data.collections[vis_collection].objects:
  32.             if obj.select_get() != unselected:
  33.                 obj.hide_set(True)
  34.  
  35.     for obj in bpy.context.view_layer.layer_collection.collection.objects:
  36.         if obj.select_get() != unselected:
  37.             obj.hide_set(True)
  38.  
  39.     global all_collections
  40.     all_collections = []
  41.  
  42.  
  43. def hide_view_clear_on_visible():
  44.  
  45.     for obj in bpy.data.objects:
  46.         obj.select_set(False)
  47.  
  48.     for vis_collection in get_visible_layer_collections():
  49.         for obj in bpy.data.collections[vis_collection].objects:
  50.             if obj.hide_get() == True:
  51.                 obj.hide_set(False)
  52.                 obj.select_set(True)
  53.  
  54.     for obj in bpy.context.view_layer.layer_collection.collection.objects:
  55.         if obj.hide_get() == True:
  56.             obj.hide_set(False)
  57.             obj.select_set(True)
  58.    
  59.     global all_collections
  60.     all_collections = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement