I have a kind of theoric question.

I've registered a PropertyGroup Class to the GreasePencil class/type, lets call it Property_A.

At the same time, this Property_A has Collection Property with different elements.

(So, I have an structure like):


My question is:

Having an element/instance of that collection, is it possible to know/get the original Grease Pencil where it is stored?

Some kind of tracing back where it belongs?

I'm new and Im not sure how bl_rna works, but maybe some kind of just getting the name of the Grease Pencil where the property is stored, so I can get it via bpy.data.grease_pencils[name]?

(I need this since for some methods, I accesed the Grease Pencil by the active Grease Pencil. But now I have to loop over all the grease pencils (using bpy.data.grease_pencils to change different things, and since those methods use the active GP, they dont work. So Im looking to replace that code for the thing Im asking).

Edit: Reformulating my question (maybe in a simpler way), I want to kind of get the data path of a property

So if I have element_zero = a_grease_pencil_object.property_a.collection[0]

somekind of method that could make something like:


And I get kind of:


So I know that I could get the name of the Grease Pencil object where it is from.

Thank you so much for the help, much appreciated!


1 Answer 1


You can very simply use repr(prop), or in your case repr(element_zero). This will return a string with the full data path from bpy.

From the repr documentation :

Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(); otherwise, the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a repr() method. If sys.displayhook() is not accessible, this function will raise RuntimeError.

If you want access to the base ID object (ie the grease pencil object) holding the property, you can use prop.id_data. See the docs for bpy.types.Struct.id_data.

  • $\begingroup$ Both options does exactly what I wanted! And I can't believe I wasn't aware of id_data until you pointed it. Thank you so much for the help friend, much appreciated! $\endgroup$
    – Ommadawn
    Commented Aug 22, 2023 at 19:36
  • 1
    $\begingroup$ @Ommadawn hehe always a pleasure to answer well documented and thought out questions. I still discover new things and tricks every day ! Cheers $\endgroup$
    – Gorgious
    Commented Aug 22, 2023 at 19:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .