4
$\begingroup$

I have a modifier object

<bpy_struct, SubsurfModifier("Subdivision") at 0x0000021FF0A3AF28>

and i was wondering how can i extract the full data_path from that modifier object without the need of using a loop on the scene to find the corresponding object

so from there i want to have this

bpy.data.objects['Icosphere'].modifiers["Subdivision"] 

and this too

bpy.data.objects['Icosphere']

which is the name of the object that has that modifier applied to it

Thanks

$\endgroup$

1 Answer 1

6
$\begingroup$

You can usually get a handle on an object's holder with bpy_struct.id_data.

import bpy

obj = bpy.data.objects["Cube"]
mod = obj.modifiers["Array"]
print(mod.id_data)

<bpy_struct, Object("Cube") at 0x000001E51A4D4808>

You can get the data path with bpy_struct.path_from_id.

print(mod.path_from_id())

modifiers["Array"]

object_path = repr(mod.id_data)
print(object_path)
full_path = f"{object_path}.{mod.path_from_id()}"
print(full_path)

bpy.data.objects["Cube"]

bpy.data.objects["Cube"].modifiers["Array"]

$\endgroup$
2
  • $\begingroup$ also repr(mod.id_data) $\endgroup$ Jun 6, 2022 at 14:18
  • 1
    $\begingroup$ @MarkusvonBroady ooh nice thank you for that ! $\endgroup$
    – Gorgious
    Jun 6, 2022 at 15:03

You must log in to answer this question.

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