I'm trying to link certain data-blocks (node groups) from a .blend file stored in the addon folder of the current blender version. I want to be able to switch blender version and for all the links to also be using the current Blender version's addon folder.
#Directory of a .blend file stored in the same place as the script
dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "example.blend")
#Links all node groups from the blend file.
with bpy.data.libraries.load(dir) as (data_from, data_to):
dir += "\\NodeTree\\"
for node_group in data_from.node_groups:
if node_group is not None:
bpy.ops.wm.link(
filepath = dir + node_group ,
directory = dir ,
filename = node_group
)
The library they are linked from has the directory stored as such after linking with this script:
//..\..\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\addon\example.blend
So if you switch to another computer or Blender version it is using the old directory (and then cannot find the correct .blend file). Not having to store the linked .blend in a user defined directory would be preferable. It just needs to work for everyone with the addon installed.