[Bf-extensions-cvs] [bb5649a8] master: collection_manager: add to contrib. Task: T69577
Ryan Inch
noreply at git.blender.org
Thu Oct 17 09:06:39 CEST 2019
Commit: bb5649a845a26e742f19a3cb924dc42cf41d858d
Author: Ryan Inch
Date: Thu Oct 17 03:05:01 2019 -0400
Branches: master
https://developer.blender.org/rBACbb5649a845a26e742f19a3cb924dc42cf41d858d
collection_manager: add to contrib. Task: T69577
===================================================================
A collection_manager/__init__.py
A collection_manager/internals.py
A collection_manager/operators.py
A collection_manager/ui.py
===================================================================
diff --git a/collection_manager/__init__.py b/collection_manager/__init__.py
new file mode 100644
index 00000000..94537381
--- /dev/null
+++ b/collection_manager/__init__.py
@@ -0,0 +1,116 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+
+""" Copyright 2011 GPL licence applies"""
+
+bl_info = {
+ "name": "Collection Manager",
+ "description": "Manage collections and their objects",
+ "author": "Ryan Inch",
+ "version": (1,0),
+ "blender": (2, 80, 0),
+ "location": "View3D - Object Mode",
+ "warning": '', # used for warning icon and text in addons panel
+ "wiki_url": "",
+ "category": "User Interface"}
+
+
+if "bpy" in locals():
+ import importlib
+
+ importlib.reload(internals)
+ importlib.reload(operators)
+ importlib.reload(ui)
+
+else:
+ from . import internals
+ from . import operators
+ from . import ui
+
+import bpy
+from bpy.props import (
+ CollectionProperty,
+ IntProperty,
+ BoolProperty,
+ )
+
+addon_keymaps = []
+
+classes = (
+ internals.CMListCollection,
+ operators.ExpandAllOperator,
+ operators.ExpandSublevelOperator,
+ operators.CMExcludeOperator,
+ operators.CMUnExcludeAllOperator,
+ operators.CMRestrictSelectOperator,
+ operators.CMUnRestrictSelectAllOperator,
+ operators.CMHideOperator,
+ operators.CMUnHideAllOperator,
+ operators.CMDisableViewportOperator,
+ operators.CMUnDisableViewportAllOperator,
+ operators.CMDisableRenderOperator,
+ operators.CMUnDisableRenderAllOperator,
+ operators.CMNewCollectionOperator,
+ operators.CMRemoveCollectionOperator,
+ operators.CMSetCollectionOperator,
+ ui.CM_UL_items,
+ ui.CollectionManager,
+ ui.CMRestrictionTogglesPanel,
+ )
+
+def register():
+ for cls in classes:
+ bpy.utils.register_class(cls)
+
+ bpy.types.Scene.CMListCollection = CollectionProperty(type=internals.CMListCollection)
+ bpy.types.Scene.CMListIndex = IntProperty()
+
+ bpy.types.Scene.show_exclude = BoolProperty(default=True, name="Exclude from View Layer")
+ bpy.types.Scene.show_selectable = BoolProperty(default=True, name="Selectable")
+ bpy.types.Scene.show_hideviewport = BoolProperty(default=True, name="Hide in Viewport")
+ bpy.types.Scene.show_disableviewport = BoolProperty(default=False, name="Disable in Viewports")
+ bpy.types.Scene.show_render = BoolProperty(default=False, name="Disable in Renders")
+
+
+ # create the global menu hotkey
+ wm = bpy.context.window_manager
+ km = wm.keyconfigs.addon.keymaps.new(name='Object Mode')
+ kmi = km.keymap_items.new('view3d.collection_manager', 'M', 'PRESS')
+ addon_keymaps.append((km, kmi))
+
+def unregister():
+ for cls in classes:
+ bpy.utils.unregister_class(cls)
+
+ del bpy.types.Scene.CMListCollection
+ del bpy.types.Scene.CMListIndex
+
+ del bpy.types.Scene.show_exclude
+ del bpy.types.Scene.show_selectable
+ del bpy.types.Scene.show_hideviewport
+ del bpy.types.Scene.show_disableviewport
+ del bpy.types.Scene.show_render
+
+ # remove keymaps when add-on is deactivated
+ for km, kmi in addon_keymaps:
+ km.keymap_items.remove(kmi)
+ addon_keymaps.clear()
+
+if __name__ == "__main__":
+ register()
diff --git a/collection_manager/internals.py b/collection_manager/internals.py
new file mode 100644
index 00000000..1734f3e0
--- /dev/null
+++ b/collection_manager/internals.py
@@ -0,0 +1,84 @@
+from bpy.types import PropertyGroup
+from bpy.props import StringProperty
+
+layer_collections = {}
+
+collection_tree = []
+
+expanded = []
+
+max_lvl = 0
+
+def get_max_lvl():
+ return max_lvl
+
+class CMListCollection(PropertyGroup):
+ name: StringProperty()
+
+
+def update_collection_tree(context):
+ global max_lvl
+ collection_tree.clear()
+ layer_collections.clear()
+ max_lvl = 0
+
+ init_laycol_list = context.view_layer.layer_collection.children
+
+ master_laycol = {"id": 0,
+ "name": context.view_layer.layer_collection.name,
+ "lvl": -1,
+ "visible": True,
+ "has_children": True,
+ "expanded": True,
+ "parent": None,
+ "children": [],
+ "ptr": context.view_layer.layer_collection
+ }
+
+ get_all_collections(context, init_laycol_list, master_laycol, collection_tree, visible=True)
+
+
+def get_all_collections(context, collections, parent, tree, level=0, visible=False):
+ for item in collections:
+ laycol = {"id": len(layer_collections) +1,
+ "name": item.name,
+ "lvl": level,
+ "visible": visible,
+ "has_children": False,
+ "expanded": False,
+ "parent": parent,
+ "children": [],
+ "ptr": item
+ }
+
+ layer_collections[item.name] = laycol
+ tree.append(laycol)
+
+ if len(item.children) > 0:
+ global max_lvl
+ max_lvl += 1
+ laycol["has_children"] = True
+
+ if item.name in expanded and laycol["visible"]:
+ laycol["expanded"] = True
+ get_all_collections(context, item.children, laycol, laycol["children"], level+1, visible=True)
+
+ else:
+ get_all_collections(context, item.children, laycol, laycol["children"], level+1)
+
+
+def update_property_group(context):
+ update_collection_tree(context)
+ context.scene.CMListCollection.clear()
+ create_property_group(context, collection_tree)
+
+
+def create_property_group(context, tree):
+ global in_filter
+
+ for laycol in tree:
+ new_cm_listitem = context.scene.CMListCollection.add()
+ new_cm_listitem.name = laycol["name"]
+
+ if laycol["has_children"]:
+ create_property_group(context, laycol["children"])
diff --git a/collection_manager/operators.py b/collection_manager/operators.py
new file mode 100644
index 00000000..6a498e55
--- /dev/null
+++ b/collection_manager/operators.py
@@ -0,0 +1,761 @@
+import bpy
+from bpy.types import Operator
+from bpy.props import (
+ BoolProperty,
+ StringProperty,
+ IntProperty
+ )
+
+from .internals import *
+
+class ExpandAllOperator(bpy.types.Operator):
+ '''Expand/Collapse all collections'''
+ bl_label = "Expand All Items"
+ bl_idname = "view3d.expand_all_items"
+
+ def execute(self, context):
+ if len(expanded) > 0:
+ expanded.clear()
+ else:
+ for laycol in layer_collections.values():
+ if laycol["ptr"].children:
+ expanded.append(laycol["name"])
+
+ # set selected row to the first row and update tree view
+ context.scene.CMListIndex = 0
+ update_property_group(context)
+
+ return {'FINISHED'}
+
+
+class ExpandSublevelOperator(bpy.types.Operator):
+ '''Expand/Collapse sublevel. Shift-Click to expand/collapse all sublevels'''
+ bl_label = "Expand Sublevel Items"
+ bl_idname = "view3d.expand_sublevel"
+
+ expand: BoolProperty()
+ name: StringProperty()
+ index: IntProperty()
+
+ def invoke(self, context, event):
+ if event.shift:
+ # expand/collapse all subcollections
+ expand = None
+
+ # check whether to expand or collapse
+ if self.name in expanded:
+ expanded.remove(self.name)
+ expand = False
+ else:
+ expanded.append(self.name)
+ expand = True
+
+ # do expanding/collapsing
+ def loop(laycol):
+ for item in laycol.children:
+ if expand:
+ if not item.name in expanded:
+ expanded.append(item.name)
+ else:
+ if item.name in expanded:
+ expanded.remove(item.name)
+
+ if len(item.children) > 0:
+ loop(item)
+
+ loop(layer_collections[self.name]["ptr"])
+
+ else:
+ # expand/collapse collection
+ if self.expand:
+ expanded.append(self.name)
+ else:
+ expanded.remove(self.name)
+
+
+ # set selected row to the collection you're expanding/collapsing and update tree view
+ context.scene.CMListIndex = self.index
+ update_property_group(context)
+
+ return {'FINISHED'}
+
+
+class CMSetCollectionOperator(bpy.types.Operator):
+ '''Click moves object to collection. Shift-Click adds/removes from collection'''
+ bl_label = "Set Collection"
+ bl_idname = "view3d.set_collection"
+
+ collection_index: IntProperty()
+ collection_name: StringProperty()
+
+ def invoke(self, context, event):
+ collection = layer_collections[self.collection_name]["ptr"].collection
+
+ if event.shift:
+ # add object to collection
+
+ # check if in collection
+ in_collection = True
+
+ for obj in context.selected_objects:
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list