[Bf-blender-cvs] [b9f4a8d75f1] asset-engine: Add more 'generic' way to select datablock to add as asset.

Bastien Montagne noreply at git.blender.org
Fri Oct 27 14:08:34 CEST 2017


Commit: b9f4a8d75f11a5d1a619752641b02200547a7661
Author: Bastien Montagne
Date:   Fri Oct 27 14:07:50 2017 +0200
Branches: asset-engine
https://developer.blender.org/rBb9f4a8d75f11a5d1a619752641b02200547a7661

Add more 'generic' way to select datablock to add as asset.

Faaarrrrr from UI/UX nice thing, but working  for now...

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

M	release/scripts/startup/bl_operators/amber/operators.py
M	release/scripts/startup/bl_operators/amber/ui.py
M	release/scripts/startup/bl_operators/amber/utils.py

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

diff --git a/release/scripts/startup/bl_operators/amber/operators.py b/release/scripts/startup/bl_operators/amber/operators.py
index 8144ac318e6..8f2499972da 100644
--- a/release/scripts/startup/bl_operators/amber/operators.py
+++ b/release/scripts/startup/bl_operators/amber/operators.py
@@ -174,19 +174,16 @@ class AmberOpsAssetAdd(Operator, AmberOpsEditing):
                               description="Copy selected datablock and its dependencies into a library .blend file "
                                           "local to the repository (mandatory when current .blend file is not saved)")
 
-    id_type = EnumProperty(bpy.types.AssetEntry.bl_rna.properties['blender_type'].enum_items_static,
-                           name="ID Type", description="Type of the datablock to create asset from")
-
-    def id_name_enum_itemf(self, context):
-        if self.id_type == 'OBJECT':
-            return [(ob.name, ob.name, "") for ob in bpy.data.objects if ob.library is None]
-        return []
-    id_name = EnumProperty(id_name_enum_itemf,
-                           name="ID Name", description="Name of the local datablock to create asset from")
+    def datablock_name_enum_itemf(self, context):
+        return ([(".".join(("objects", ob.name)), ob.name, "") for ob in bpy.data.objects if ob.library is None] +
+                [(".".join(("materials", mat.name)), mat.name, "") for mat in bpy.data.materials if mat.library is None] + 
+                [(".".join(("textures", tex.name)), tex.name, "") for tex in bpy.data.textures if tex.library is None])
+    datablock_name = EnumProperty(items=datablock_name_enum_itemf,
+                                  name="ID Name", description="Name of the local datablock to create asset from")
 
     @staticmethod  # self is not op instance here, but menu generated by window manager...
     def datablocks_select_menu(self, context):
-        self.layout.operator_menu_enum("AMBER_OT_asset_add", "id_name").id_type = 'OBJECT'
+        self.layout.operator_menu_enum("AMBER_OT_asset_add", "datablock_name")
 
     def execute(self, context):
         import time
@@ -206,13 +203,9 @@ class AmberOpsAssetAdd(Operator, AmberOpsEditing):
         elif self.active_type == 'MATERIAL':
             datablock = context.active_object.material_slots[context.active_object.active_material_index].material
 
-        if datablock is None and self.id_name:
-            if self.id_type == 'OBJECT':
-                datablock = bpy.data.objects[self.id_name]
-            elif self.id_type == 'MATERIAL':
-                datablock = bpy.data.materials[self.id_name]
-            elif self.id_type == 'TEXTURE':
-                datablock = bpy.data.textures[self.id_name]
+        if datablock is None and self.datablock_name:
+            datablock_type, datablock_name = self.datablock_name.split('.', 1)
+            datablock = getattr(bpy.data, datablock_type)[datablock_name]
 
         if datablock is None:
             self.report({'INFO'}, "No suitable active datablock found to create a new asset")
@@ -277,9 +270,9 @@ class AmberOpsAssetAdd(Operator, AmberOpsEditing):
         return {'FINISHED'}
 
     def invoke(self, context, event):
-        if self.active_type == 'NONE':
-            context.window_manager.popup_menu(self.datablocks_select_menu, "Select A Data-block")
-            return {'FINISHED'}
+        #~ if self.active_type == 'NONE':
+            #~ context.window_manager.popup_menu(self.datablocks_select_menu, "Select A Data-block")
+            #~ return {'FINISHED'}
         return self.execute(context)
 
 
diff --git a/release/scripts/startup/bl_operators/amber/ui.py b/release/scripts/startup/bl_operators/amber/ui.py
index 6d76cf62501..a62f5f609f4 100644
--- a/release/scripts/startup/bl_operators/amber/ui.py
+++ b/release/scripts/startup/bl_operators/amber/ui.py
@@ -185,7 +185,7 @@ class AMBER_UL_tags(UIList):
     use_order_name = bpy.props.BoolProperty(name="Name", default=False, options=set(),
                                             description="Sort tags by their name (case-insensitive)",
                                             update=_gen_order_update("use_order_name", "use_order_importance"))
-    use_order_importance = bpy.props.BoolProperty(name="Importance", default=False, options=set(),
+    use_order_importance = bpy.props.BoolProperty(name="Importance", default=True, options=set(),
                                                   description="Sort tags by their weight",
                                                   update=_gen_order_update("use_order_importance", "use_order_name"))
 
@@ -276,7 +276,7 @@ class AMBER_PT_assets(Panel, AmberPanelEditing):
         col.operator("AMBER_OT_asset_add", text="", icon='OBJECT_DATA').active_type = 'OBJECT'
         col.operator("AMBER_OT_asset_add", text="", icon='MATERIAL_DATA').active_type = 'MATERIAL'
         col.operator_context = 'INVOKE_DEFAULT'
-        col.operator("AMBER_OT_asset_add", text="", icon='ZOOMIN')
+        col.operator_menu_enum("AMBER_OT_asset_add", "datablock_name", text="", icon='ZOOMIN')
         col.operator("AMBER_OT_asset_delete", text="", icon='ZOOMOUT')
 
         row = self.layout.row()
diff --git a/release/scripts/startup/bl_operators/amber/utils.py b/release/scripts/startup/bl_operators/amber/utils.py
index 0f09c75ef06..d826100146a 100644
--- a/release/scripts/startup/bl_operators/amber/utils.py
+++ b/release/scripts/startup/bl_operators/amber/utils.py
@@ -43,6 +43,7 @@ BLENDER_TYPES_TO_PATH = {
     bpy.types.Object: "Object",
     bpy.types.Group: "Group",
     bpy.types.Material: "Material",
+    bpy.types.Texture: "Texture",
     # TODO complete this!
 }
 
@@ -50,6 +51,7 @@ BLENDER_TYPES_TO_ENUMVAL = {
     bpy.types.Object: 'OBJECT',
     bpy.types.Group: 'GROUP',
     bpy.types.Material: 'MATERIAL',
+    bpy.types.Texture: 'TEXTURE',
     # TODO complete this!
 }



More information about the Bf-blender-cvs mailing list