Okazaki Naoki
Okazaki Naoki

Reputation: 47

How to get Blender script path that is running

How do I get the full path of the current file's directory?

Yes, I already tried these methods. They all give me the folder that contains Blender.exe which is D:\program\Blender 2.90

And what I supposed to get is C:\Users\username\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\someAddonFolder right?

Is something changed in version 2.9? Without the Blender environment, I mean run under normal Python. Methods from that topic all work well. Did I miss something?

The old way I made the script work is by putting .blend .json .py all together in the same folder. and refer to the relative path using //

Upvotes: 2

Views: 2388

Answers (2)

SandPiper
SandPiper

Reputation: 2906

I don't know when this changed specifically, but as of at least Blender 4.0 the accepted answer no longer works. Do this instead:

import bpy
import os

blender_addon_path = os.path.join(bpy.utils.script_path_user(), "addons")

Upvotes: 0

Okazaki Naoki
Okazaki Naoki

Reputation: 47

bpy.utils.user_resource('SCRIPTS', "addons")

use this code can get you the path your custom addon you install at. for me, it's 'C:\Users\Naoki\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons'

found the answer over here: https://blender.stackexchange.com/questions/20850/how-to-automatically-get-a-add-on-folders-path-regardless-of-os

Upvotes: 2

Related Questions