[Bf-blender-cvs] [557b3d2762a] master: Assets: Add BPY function to mark and clear assets

Julian Eisel noreply at git.blender.org
Tue Apr 20 22:37:39 CEST 2021


Commit: 557b3d2762a62af80b4ef0778e012d6eff2c6a47
Author: Julian Eisel
Date:   Tue Apr 20 22:29:44 2021 +0200
Branches: master
https://developer.blender.org/rB557b3d2762a62af80b4ef0778e012d6eff2c6a47

Assets: Add BPY function to mark and clear assets

Adds `mark_asset()` and `clear_asset()` to ID data-blocks, e.g.
`bpy.context.active_object.mark_asset()`. They essentially do the same as the
mark and clear asset operators.

Scripts are generally discouraged from using operators where possible, but we
need to provide API functions to use instead. In this case it means scripts
don't have to override context to pass an ID to the operator.

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

M	source/blender/makesrna/intern/rna_ID.c

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

diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 657af98f5fe..e1480dc2822 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -148,6 +148,8 @@ static const EnumPropertyItem rna_enum_override_library_property_operation_items
 #  include "DEG_depsgraph_build.h"
 #  include "DEG_depsgraph_query.h"
 
+#  include "ED_asset.h"
+
 #  include "WM_api.h"
 
 void rna_ID_override_library_property_operation_refname_get(PointerRNA *ptr, char *value)
@@ -575,6 +577,22 @@ static ID *rna_ID_copy(ID *id, Main *bmain)
   return newid;
 }
 
+static void rna_ID_mark_asset(ID *id, bContext *C)
+{
+  ED_asset_mark_id(C, id);
+
+  WM_main_add_notifier(NC_ID | NA_EDITED, NULL);
+  WM_main_add_notifier(NC_ASSET | NA_ADDED, NULL);
+}
+
+static void rna_ID_clear_asset(ID *id)
+{
+  ED_asset_clear_id(id);
+
+  WM_main_add_notifier(NC_ID | NA_EDITED, NULL);
+  WM_main_add_notifier(NC_ASSET | NA_REMOVED, NULL);
+}
+
 static ID *rna_ID_override_create(ID *id, Main *bmain, bool remap_local_usages)
 {
   if (!ID_IS_OVERRIDABLE_LIBRARY(id)) {
@@ -1716,6 +1734,18 @@ static void rna_def_ID(BlenderRNA *brna)
   parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID");
   RNA_def_function_return(func, parm);
 
+  func = RNA_def_function(srna, "mark_asset", "rna_ID_mark_asset");
+  RNA_def_function_ui_description(
+      func,
+      "Enable easier reuse of the data-block through the Asset Browser, with the help of "
+      "customizable metadata (like previews, descriptions and tags)");
+  RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+
+  func = RNA_def_function(srna, "clear_asset", "rna_ID_clear_asset");
+  RNA_def_function_ui_description(
+      func,
+      "Delete all asset metadata and turn the asset data-block back into a normal data-block");
+
   func = RNA_def_function(srna, "override_create", "rna_ID_override_create");
   RNA_def_function_ui_description(func,
                                   "Create an overridden local copy of this linked data-block (not "



More information about the Bf-blender-cvs mailing list