GPv3: Python API for frame, drawing and drawing attributes #124787

Merged
Falk David merged 22 commits from filedescriptor/blender:gpv3-drawing-python-api into main 2024-07-26 16:30:21 +02:00
2 changed files with 25 additions and 0 deletions
Showing only changes of commit d5d345d70b - Show all commits

View File

@ -151,7 +151,14 @@ class Drawing : public ::GreasePencilDrawing {
* Returns true for when this drawing has more than one user.
*/
bool is_instanced() const;
/**
* Return true if this drawing has at least one user.
*/
bool has_users() const;
/**
* Return the number of users (keyframes) of this drawing.
*/
int user_count() const;
};
static_assert(sizeof(Drawing) == sizeof(::GreasePencilDrawing));
@ -742,6 +749,10 @@ inline bool Drawing::has_users() const
{
return this->runtime->user_count.load(std::memory_order_relaxed) > 0;
}
inline int Drawing::user_count() const
{
return this->runtime->user_count.load(std::memory_order_relaxed);
}
inline bool TreeNode::is_group() const
{

View File

@ -109,6 +109,13 @@ static void rna_grease_pencil_dependency_update(Main *bmain, Scene * /*scene*/,
WM_main_add_notifier(NC_GPENCIL | NA_EDITED, rna_grease_pencil(ptr));
}
static int rna_Drawing_user_count_get(PointerRNA *ptr)
{
using namespace blender::bke::greasepencil;
const GreasePencilDrawing *drawing = static_cast<const GreasePencilDrawing *>(ptr->data);
return drawing->wrap().user_count();
}
static void rna_GreasePencilLayer_frames_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
using namespace blender::bke::greasepencil;
@ -774,6 +781,13 @@ static void rna_def_grease_pencil_drawing(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Type", "Drawing type");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_grease_pencil_update");
/* User Count. */
prop = RNA_def_property(srna, "user_count", PROP_INT, PROP_NONE);
RNA_def_property_int_funcs(prop, "rna_Drawing_user_count_get", nullptr, nullptr);
RNA_def_parameter_clear_flags(prop, PROP_EDITABLE, ParameterFlag(0));
RNA_def_property_ui_text(prop, "User Count", "The number of keyframes this drawing is used by");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_grease_pencil_update");
/* Attributes. */
rna_def_attributes_common(srna, AttributeOwnerType::GreasePencilDrawing);
}