1
$\begingroup$

I have a Blender python script in my Blender file

import bpy
print(variable)

and an external .py file in the same directory as the .blend file.

variable = "spam"

I want to import the external file into Blender using a relative path.

$\endgroup$
1
  • 1
    $\begingroup$ Please add more details to your question, it is currently unclear what you mean. $\endgroup$ Commented Jan 7, 2017 at 17:38

1 Answer 1

3
$\begingroup$

You can append the path to your script

import bpy, sys
sys.path.append('//myscript.py')
import myscript
$\endgroup$
4
  • $\begingroup$ The second file is not in the blend file but in the same directory as the blend file $\endgroup$ Commented Jan 7, 2017 at 18:14
  • $\begingroup$ This code is for if the script is in the same directory as the script calling it. Is that not the case? $\endgroup$ Commented Jan 7, 2017 at 18:16
  • $\begingroup$ no, because it is in the same directory as the .blend file but not IN the .blend file $\endgroup$ Commented Jan 7, 2017 at 18:23
  • $\begingroup$ Edited my answer. $\endgroup$ Commented Jan 7, 2017 at 19:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.