[Bf-extensions-cvs] [bd9a87ca] blender-v2.79a-release: Dynamic Context Menu: Disable Group Instance if there are no Groups

lijenstina noreply at git.blender.org
Mon Jan 1 16:36:26 CET 2018


Commit: bd9a87ca2539e8bb81c2f44ec7d3a7aa3c85fd9e
Author: lijenstina
Date:   Tue Sep 26 21:08:38 2017 +0200
Branches: blender-v2.79a-release
https://developer.blender.org/rBAbd9a87ca2539e8bb81c2f44ec7d3a7aa3c85fd9e

Dynamic Context Menu: Disable Group Instance if there are no Groups

Bump version to 1.8.6

Cover the case when the bpy.data.groups is zero
disable the entry as it will have just an empty menu
Add the case when there is more than 10 groups
similar to the space_view3d

===================================================================

M	space_view3d_spacebar_menu.py

===================================================================

diff --git a/space_view3d_spacebar_menu.py b/space_view3d_spacebar_menu.py
index f3b6364d..3ba517e7 100644
--- a/space_view3d_spacebar_menu.py
+++ b/space_view3d_spacebar_menu.py
@@ -20,7 +20,7 @@
 bl_info = {
     "name": "Dynamic Context Menu",
     "author": "meta-androcto",
-    "version": (1, 8, 5),
+    "version": (1, 8, 6),
     "blender": (2, 77, 0),
     "location": "View3D > Spacebar",
     "description": "Object Mode Context Sensitive Spacebar Menu",
@@ -849,9 +849,19 @@ class VIEW3D_MT_AddMenu(Menu):
                                   icon='FORCE_FORCE')
         layout.menu("VIEW3D_MT_object_quick_effects", text="Quick Effects", icon='PARTICLES')
         UseSeparator(self, context)
-        layout.operator_menu_enum("object.group_instance_add", "group",
-                                  text="Group Instance",
-                                  icon='GROUP_VERTEX')
+
+        has_groups = (len(bpy.data.groups) > 0)
+        col_group = layout.column()
+        col_group.enabled = has_groups
+
+        if not has_groups or len(bpy.data.groups) > 10:
+            col_group.operator_context = 'INVOKE_REGION_WIN'
+            col_group.operator("object.group_instance_add",
+                                text="Group Instance..." if has_groups else "No Groups in Data",
+                                icon='GROUP_VERTEX')
+        else:
+            col_group.operator_menu_enum("object.group_instance_add", "group",
+                                text="Group Instance", icon='GROUP_VERTEX')
 
 
 # ********** Object Manipulator **********



More information about the Bf-extensions-cvs mailing list