If I wan't to import another python script(Test_script_1) and also run it through my python script(Test_Script_2)
Can this be done through init.py script ?
Can anyone tell me how to do that ?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
Here's what I've just done, it seems to work.
My paths are:
scripts path -
mainscript path -
blender file path -
C:\Users\Drew\Documents\Development\graphics\3D Assets\Prototype\Blender Projects\Templates\Builder.blend
I wanted to be able to import scripts from a completely different but known relative directory. So here is how I tackled it:
import bpy, sys from pathlib import Path path = Path(bpy.data.filepath) sys.path.append(str(path.parent.parent.parent.parent.parent) + "\\Blender Scripts") import test_import test_import.print_a_message()
The number of parents determines where in the directory structure I am, and then I add the rest of the path as a string.
Yes, of course this can be done. If you have an add-on with its folder and
__init__.py inside it, if you have other files like
file.py in the same folder you just import stuff from it like this:
from .file import Some_stuff
[Blender's installation folder]\[version]\scripts\addons\ and see how it's done with any of the add-ons in the folders there.