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.
This commit is contained in:
parent
847579b422
commit
557b3d2762
|
@ -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 "
|
||||
|
|
Loading…
Reference in New Issue